Merge lp:~mterry/duplicity/797758 into lp:duplicity/0.6

Proposed by Michael Terry
Status: Merged
Merged at revision: 749
Proposed branch: lp:~mterry/duplicity/797758
Merge into: lp:duplicity/0.6
Diff against target: 374 lines (+37/-37)
17 files modified
duplicity-bin (+2/-2)
duplicity/backend.py (+9/-9)
duplicity/backends/ftpbackend.py (+1/-1)
duplicity/backends/ftpsbackend.py (+1/-1)
duplicity/backends/hsibackend.py (+1/-1)
duplicity/backends/imapbackend.py (+1/-1)
duplicity/backends/localbackend.py (+1/-1)
duplicity/collections.py (+2/-2)
duplicity/commandline.py (+3/-3)
duplicity/dup_temp.py (+1/-1)
duplicity/gpg.py (+6/-6)
duplicity/manifest.py (+1/-1)
duplicity/pexpect.py (+3/-3)
duplicity/selection.py (+1/-1)
duplicity/tempdir.py (+2/-2)
testing/backendtest.py (+1/-1)
testing/config.py.tmpl (+1/-1)
To merge this branch: bzr merge lp:~mterry/duplicity/797758
Reviewer Review Type Date Requested Status
duplicity-team Pending
Review via email: mp+64942@code.launchpad.net

Description of the change

From bug 797758:

1) Duplicity calls self.last_backup.delete() during a restart
2) Which executes the following:

try:
    self.backend.delete(rfn)
except:
    log.Debug("BackupSet.delete: missing %s" % rfn)
    pass

3) If the backend.delete function encounters a FatalError, sys.exit will be called, which should close duplicity.
4) But the way that except clause is written, it won't. Blanket "except:" clauses will catch even SystemExit exceptions. See http://stackoverflow.com/questions/730764/try-catch-in-python

The fix is to use "except Exception:" instead. This branch does that for all except: lines. I assume that is correct, that we never intentionally want to block SystemExit or KeyboardInterrupt?

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-bin'
2--- duplicity-bin 2011-06-13 21:59:26 +0000
3+++ duplicity-bin 2011-06-17 06:26:31 +0000
4@@ -895,7 +895,7 @@
5 def next(self, size):
6 try:
7 res = Block(self.fileobj.read(size))
8- except:
9+ except Exception:
10 if hasattr(self.fileobj, 'name'):
11 name = self.fileobj.name
12 else:
13@@ -1011,7 +1011,7 @@
14 tempfs = os.path.sep.join(tempname.split(os.path.sep)[:-2])
15 try:
16 stats = os.statvfs(tempfs)
17- except:
18+ except Exception:
19 log.FatalError(_("Unable to get free space on temp."),
20 log.ErrorCode.get_freespace_failed)
21 # Calculate space we need for at least 2 volumes of full or inc
22
23=== modified file 'duplicity/backend.py'
24--- duplicity/backend.py 2011-06-13 15:41:28 +0000
25+++ duplicity/backend.py 2011-06-17 06:26:31 +0000
26@@ -76,7 +76,7 @@
27 try:
28 __import__(imp)
29 res = "Succeeded"
30- except:
31+ except Exception:
32 res = "Failed: " + str(sys.exc_info()[1])
33 log.Info("Import of %s %s" % (imp, res))
34 else:
35@@ -216,27 +216,27 @@
36
37 try:
38 pu = urlparser.urlparse(url_string)
39- except:
40+ except Exception:
41 raise InvalidBackendURL("Syntax error in: %s" % url_string)
42
43 try:
44 self.scheme = pu.scheme
45- except:
46+ except Exception:
47 raise InvalidBackendURL("Syntax error (scheme) in: %s" % url_string)
48
49 try:
50 self.netloc = pu.netloc
51- except:
52+ except Exception:
53 raise InvalidBackendURL("Syntax error (netloc) in: %s" % url_string)
54
55 try:
56 self.path = pu.path
57- except:
58+ except Exception:
59 raise InvalidBackendURL("Syntax error (path) in: %s" % url_string)
60
61 try:
62 self.username = pu.username
63- except:
64+ except Exception:
65 raise InvalidBackendURL("Syntax error (username) in: %s" % url_string)
66 if self.username:
67 self.username = urllib.unquote(pu.username)
68@@ -245,7 +245,7 @@
69
70 try:
71 self.password = pu.password
72- except:
73+ except Exception:
74 raise InvalidBackendURL("Syntax error (password) in: %s" % url_string)
75 if self.password:
76 self.password = urllib.unquote(self.password)
77@@ -254,14 +254,14 @@
78
79 try:
80 self.hostname = pu.hostname
81- except:
82+ except Exception:
83 raise InvalidBackendURL("Syntax error (hostname) in: %s" % url_string)
84
85 # init to None, overwrite with actual value on success
86 self.port = None
87 try:
88 self.port = pu.port
89- except:
90+ except Exception:
91 # old style rsync://host::[/]dest, are still valid, though they contain no port
92 if not ( self.scheme in ['rsync'] and re.search('::[^:]*$', self.url_string)):
93 raise InvalidBackendURL("Syntax error (port) in: %s A%s B%s C%s" % (url_string, (self.scheme in ['rsync']), re.search('::[^:]+$', self.netloc), self.netloc ) )
94
95=== modified file 'duplicity/backends/ftpbackend.py'
96--- duplicity/backends/ftpbackend.py 2011-06-12 11:36:26 +0000
97+++ duplicity/backends/ftpbackend.py 2011-06-17 06:26:31 +0000
98@@ -38,7 +38,7 @@
99 p = os.popen("ncftpls -v")
100 fout = p.read()
101 ret = p.close()
102- except:
103+ except Exception:
104 pass
105 # the expected error is 8 in the high-byte and some output
106 if ret != 0x0800 or not fout:
107
108=== modified file 'duplicity/backends/ftpsbackend.py'
109--- duplicity/backends/ftpsbackend.py 2011-03-06 15:12:33 +0000
110+++ duplicity/backends/ftpsbackend.py 2011-06-17 06:26:31 +0000
111@@ -41,7 +41,7 @@
112 p = os.popen("lftp --version")
113 fout = p.read()
114 ret = p.close()
115- except:
116+ except Exception:
117 pass
118 # there is no output if lftp not found
119 if not fout:
120
121=== modified file 'duplicity/backends/hsibackend.py'
122--- duplicity/backends/hsibackend.py 2010-07-22 19:15:11 +0000
123+++ duplicity/backends/hsibackend.py 2011-06-17 06:26:31 +0000
124@@ -41,7 +41,7 @@
125 commandline = '%s "put %s : %s%s"' % (hsi_command,source_path.name,self.remote_prefix,remote_filename)
126 try:
127 self.run_command(commandline)
128- except:
129+ except Exception:
130 print commandline
131
132 def get(self, remote_filename, local_path):
133
134=== modified file 'duplicity/backends/imapbackend.py'
135--- duplicity/backends/imapbackend.py 2010-07-22 19:15:11 +0000
136+++ duplicity/backends/imapbackend.py 2011-06-17 06:26:31 +0000
137@@ -75,7 +75,7 @@
138 # Try to close the connection cleanly
139 try:
140 self._conn.close()
141- except:
142+ except Exception:
143 pass
144
145 if (parsed_url.scheme == "imap"):
146
147=== modified file 'duplicity/backends/localbackend.py'
148--- duplicity/backends/localbackend.py 2011-06-12 11:12:30 +0000
149+++ duplicity/backends/localbackend.py 2011-06-17 06:26:31 +0000
150@@ -87,7 +87,7 @@
151 """List files in that directory"""
152 try:
153 os.makedirs(self.remote_pathdir.base)
154- except:
155+ except Exception:
156 pass
157 try:
158 return self.remote_pathdir.listdir()
159
160=== modified file 'duplicity/collections.py'
161--- duplicity/collections.py 2010-11-20 15:39:00 +0000
162+++ duplicity/collections.py 2011-06-17 06:26:31 +0000
163@@ -137,7 +137,7 @@
164 rfn.reverse()
165 try:
166 self.backend.delete(rfn)
167- except:
168+ except Exception:
169 log.Debug("BackupSet.delete: missing %s" % rfn)
170 pass
171 for lfn in globals.archive_dir.listdir():
172@@ -153,7 +153,7 @@
173 # which is bad if running non-interactive with encrypt-key
174 try:
175 globals.archive_dir.append(lfn).delete()
176- except:
177+ except Exception:
178 log.Debug("BackupSet.delete: missing %s" % lfn)
179 pass
180
181
182=== modified file 'duplicity/commandline.py'
183--- duplicity/commandline.py 2011-06-12 11:05:30 +0000
184+++ duplicity/commandline.py 2011-06-17 06:26:31 +0000
185@@ -518,7 +518,7 @@
186 elif cmd == "remove-older-than":
187 try:
188 arg = args.pop(0)
189- except:
190+ except Exception:
191 command_line_error("Missing time string for remove-older-than")
192 globals.remove_time = dup_time.genstrtotime(arg)
193 num_expect = 1
194@@ -529,7 +529,7 @@
195 globals.remove_all_inc_of_but_n_full_mode = True
196 try:
197 arg = args.pop(0)
198- except:
199+ except Exception:
200 command_line_error("Missing count for " + cmd)
201 globals.keep_chains = int(arg)
202 if not globals.keep_chains > 0:
203@@ -767,7 +767,7 @@
204 if not os.path.exists(dirstring):
205 try:
206 os.makedirs(dirstring)
207- except:
208+ except Exception:
209 pass
210 archive_dir = path.Path(dirstring)
211 if not archive_dir.isdir():
212
213=== modified file 'duplicity/dup_temp.py'
214--- duplicity/dup_temp.py 2011-04-16 20:25:01 +0000
215+++ duplicity/dup_temp.py 2011-06-17 06:26:31 +0000
216@@ -244,7 +244,7 @@
217 def next(self, size):
218 try:
219 res = Block(self.fp.read(size))
220- except:
221+ except Exception:
222 log.FatalError(_("Failed to read %s: %s") %
223 (self.src.name, sys.exc_info()),
224 log.ErrorCode.generic)
225
226=== modified file 'duplicity/gpg.py'
227--- duplicity/gpg.py 2011-04-16 20:25:01 +0000
228+++ duplicity/gpg.py 2011-06-17 06:26:31 +0000
229@@ -150,7 +150,7 @@
230 def write(self, buf):
231 try:
232 res = self.gpg_input.write(buf)
233- except:
234+ except Exception:
235 self.gpg_failed()
236 return res
237
238@@ -171,13 +171,13 @@
239 if self.encrypt:
240 try:
241 self.gpg_input.close()
242- except:
243+ except Exception:
244 self.gpg_failed()
245 if self.status_fp:
246 self.set_signature()
247 try:
248 self.gpg_process.wait()
249- except:
250+ except Exception:
251 self.gpg_failed()
252 else:
253 res = 1
254@@ -185,17 +185,17 @@
255 # discard remaining output to avoid GPG error
256 try:
257 res = self.gpg_output.read(blocksize)
258- except:
259+ except Exception:
260 self.gpg_failed()
261 try:
262 self.gpg_output.close()
263- except:
264+ except Exception:
265 self.gpg_failed()
266 if self.status_fp:
267 self.set_signature()
268 try:
269 self.gpg_process.wait()
270- except:
271+ except Exception:
272 self.gpg_failed()
273 self.logger_fp.close()
274 self.stderr_fp.close()
275
276=== modified file 'duplicity/manifest.py'
277--- duplicity/manifest.py 2011-03-06 16:19:53 +0000
278+++ duplicity/manifest.py 2011-06-17 06:26:31 +0000
279@@ -132,7 +132,7 @@
280 """
281 try:
282 del self.volume_info_dict[vol_num]
283- except:
284+ except Exception:
285 raise ManifestError("Volume %d not present in manifest" % (vol_num,))
286
287 def to_string(self):
288
289=== modified file 'duplicity/pexpect.py'
290--- duplicity/pexpect.py 2010-07-22 19:15:11 +0000
291+++ duplicity/pexpect.py 2011-06-17 06:26:31 +0000
292@@ -534,7 +534,7 @@
293 try:
294 self.child_fd = sys.stdout.fileno() # used by setwinsize()
295 self.setwinsize(24, 80)
296- except:
297+ except Exception:
298 # Some platforms do not like setwinsize (Cygwin).
299 # This will cause problem when running applications that
300 # are very picky about window size.
301@@ -624,7 +624,7 @@
302 if fd >= 0:
303 os.close(fd)
304 raise ExceptionPexpect, "Error! We are not disconnected from a controlling tty."
305- except:
306+ except Exception:
307 # Good! We are disconnected from a controlling tty.
308 pass
309
310@@ -1407,7 +1407,7 @@
311 self.match = None
312 self.match_index = None
313 raise TIMEOUT (str(e) + '\n' + str(self))
314- except:
315+ except Exception:
316 self.before = incoming
317 self.after = None
318 self.match = None
319
320=== modified file 'duplicity/selection.py'
321--- duplicity/selection.py 2011-06-12 10:16:35 +0000
322+++ duplicity/selection.py 2011-06-17 06:26:31 +0000
323@@ -457,7 +457,7 @@
324 assert include == 0 or include == 1
325 try:
326 regexp = re.compile(regexp_string)
327- except:
328+ except Exception:
329 log.Warn(_("Error compiling regular expression %s") % regexp_string)
330 raise
331
332
333=== modified file 'duplicity/tempdir.py'
334--- duplicity/tempdir.py 2009-06-06 17:35:19 +0000
335+++ duplicity/tempdir.py 2011-06-17 06:26:31 +0000
336@@ -231,12 +231,12 @@
337 try:
338 log.Debug(_("Removing still remembered temporary file %s") % (file,))
339 os.unlink(file)
340- except:
341+ except Exception:
342 log.Info(_("Cleanup of temporary file %s failed") % (file,))
343 pass
344 try:
345 os.rmdir(self.__dir)
346- except:
347+ except Exception:
348 log.Warn(_("Cleanup of temporary directory %s failed - this is probably a bug.") % (self.__dir,))
349 pass
350 self.__pending = None
351
352=== modified file 'testing/backendtest.py'
353--- testing/backendtest.py 2011-03-08 19:45:47 +0000
354+++ testing/backendtest.py 2011-06-17 06:26:31 +0000
355@@ -27,7 +27,7 @@
356 try:
357 import duplicity.backends.giobackend
358 gio_available = True
359-except:
360+except Exception:
361 gio_available = False
362 from duplicity.errors import * #@UnusedWildImport
363 from duplicity import path, file_naming, dup_time, globals, gpg
364
365=== modified file 'testing/config.py.tmpl'
366--- testing/config.py.tmpl 2010-11-20 15:39:00 +0000
367+++ testing/config.py.tmpl 2011-06-17 06:26:31 +0000
368@@ -112,5 +112,5 @@
369 else:
370 try:
371 del os.environ[varname]
372- except:
373+ except Exception:
374 pass

Subscribers

People subscribed via source and target branches

to all changes: