Merge lp:~mterry/duplicity/gio-pydrive-fsdecode into lp:~duplicity-team/duplicity/0.8-series

Proposed by Michael Terry
Status: Merged
Merged at revision: 1370
Proposed branch: lp:~mterry/duplicity/gio-pydrive-fsdecode
Merge into: lp:~duplicity-team/duplicity/0.8-series
Diff against target: 99 lines (+16/-10)
2 files modified
duplicity/backends/giobackend.py (+4/-4)
duplicity/backends/pydrivebackend.py (+12/-6)
To merge this branch: bzr merge lp:~mterry/duplicity/gio-pydrive-fsdecode
Reviewer Review Type Date Requested Status
duplicity-team Pending
Review via email: mp+368101@code.launchpad.net

Commit message

Fix gio and pydrive backends to use fsdecode

Description of the change

It looks like the gio and pydrive backends have some issues in 0.8.00.

If I'm gathering correctly, backends are given byte string filenames. Both those backends' libraries were expecting unicode, so we have to decode first.

I also added some missing exception imports in pydrive.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'duplicity/backends/giobackend.py'
2--- duplicity/backends/giobackend.py 2018-07-23 14:55:39 +0000
3+++ duplicity/backends/giobackend.py 2019-05-29 23:37:47 +0000
4@@ -139,12 +139,12 @@
5 def _put(self, source_path, remote_filename):
6 from gi.repository import Gio # @UnresolvedImport # pylint: disable=import-error
7 source_file = Gio.File.new_for_path(source_path.name)
8- target_file = self.remote_file.get_child_for_display_name(remote_filename)
9+ target_file = self.remote_file.get_child_for_display_name(util.fsdecode(remote_filename))
10 self.__copy_file(source_file, target_file)
11
12 def _get(self, filename, local_path):
13 from gi.repository import Gio # @UnresolvedImport # pylint: disable=import-error
14- source_file = self.remote_file.get_child_for_display_name(filename)
15+ source_file = self.remote_file.get_child_for_display_name(util.fsdecode(filename))
16 target_file = Gio.File.new_for_path(local_path.name)
17 self.__copy_file(source_file, target_file)
18
19@@ -165,12 +165,12 @@
20 return files
21
22 def _delete(self, filename):
23- target_file = self.remote_file.get_child_for_display_name(filename)
24+ target_file = self.remote_file.get_child_for_display_name(util.fsdecode(filename))
25 target_file.delete(None)
26
27 def _query(self, filename):
28 from gi.repository import Gio # @UnresolvedImport # pylint: disable=import-error
29- target_file = self.remote_file.get_child_for_display_name(filename)
30+ target_file = self.remote_file.get_child_for_display_name(util.fsdecode(filename))
31 info = target_file.query_info(Gio.FILE_ATTRIBUTE_STANDARD_SIZE,
32 Gio.FileQueryInfoFlags.NONE, None)
33 return {u'size': info.get_size()}
34
35=== modified file 'duplicity/backends/pydrivebackend.py'
36--- duplicity/backends/pydrivebackend.py 2019-05-19 16:14:00 +0000
37+++ duplicity/backends/pydrivebackend.py 2019-05-29 23:37:47 +0000
38@@ -23,6 +23,7 @@
39
40 import duplicity.backend
41 from duplicity import log
42+from duplicity import util
43 from duplicity.errors import BackendException
44
45
46@@ -115,6 +116,10 @@
47 self.id_cache = {}
48
49 def file_by_name(self, filename):
50+ from pydrive.files import ApiRequestError
51+
52+ filename = util.fsdecode(filename) # PyDrive deals with unicode filenames
53+
54 if filename in self.id_cache:
55 # It might since have been locally moved, renamed or deleted, so we
56 # need to validate the entry.
57@@ -164,20 +169,20 @@
58 drive_file = self.file_by_name(remote_filename)
59 if drive_file is None:
60 # No existing file, make a new one
61- drive_file = self.drive.CreateFile({u'title': remote_filename,
62+ drive_file = self.drive.CreateFile({u'title': util.fsdecode(remote_filename),
63 u'parents': [{u"kind": u"drive#fileLink",
64 u"id": self.folder}]})
65- log.Info(u"PyDrive backend: creating new file '%s'" % (remote_filename,))
66+ log.Info(u"PyDrive backend: creating new file '%s'" % (util.fsdecode(remote_filename),))
67 else:
68 log.Info(u"PyDrive backend: replacing existing file '%s' with id '%s'" % (
69- remote_filename, drive_file[u'id']))
70- drive_file.SetContentFile(source_path.name)
71+ util.fsdecode(remote_filename), drive_file[u'id']))
72+ drive_file.SetContentFile(util.fsdecode(source_path.name))
73 drive_file.Upload()
74 self.id_cache[remote_filename] = drive_file[u'id']
75
76 def _get(self, remote_filename, local_path):
77 drive_file = self.file_by_name(remote_filename)
78- drive_file.GetContentFile(local_path.name)
79+ drive_file.GetContentFile(util.fsdecode(local_path.name))
80
81 def _list(self):
82 drive_files = self.drive.ListFile({
83@@ -198,7 +203,7 @@
84 if file_id != u'':
85 self.drive.auth.service.files().delete(fileId=file_id).execute()
86 else:
87- log.Warn(u"File '%s' does not exist while trying to delete it" % (filename,))
88+ log.Warn(u"File '%s' does not exist while trying to delete it" % (util.fsdecode(filename),))
89
90 def _query(self, filename):
91 drive_file = self.file_by_name(filename)
92@@ -209,6 +214,7 @@
93 return {u'size': size}
94
95 def _error_code(self, operation, error):
96+ from pydrive.files import ApiRequestError, FileNotUploadedError
97 if isinstance(error, FileNotUploadedError):
98 return log.ErrorCode.backend_not_found
99 elif isinstance(error, ApiRequestError):

Subscribers

People subscribed via source and target branches