From: Johannes Berg Date: Sat, 16 May 2020 07:03:31 +0000 (+0200) Subject: save: close files immediately X-Git-Tag: 0.30.1~3 X-Git-Url: https://arthur.barton.de/gitweb/?a=commitdiff_plain;h=da2424105791f9d732c9f429c562d47cd4c7382e;hp=d91cf5c026bb118076e2e16303760e0181fbd508;p=bup.git save: close files immediately Use a with statement to close all files immediately after hashsplitting. There's also no need to have two except clauses, so unify them to simplify this change. Signed-off-by: Johannes Berg Reviewed-by: Rob Browning Tested-by: Rob Browning (cherry picked from commit 0c009932e7eae09badf847b951025f2bad4c271f) [rlb@defaultvalue.org: adjusted for 0.30.x] --- diff --git a/cmd/save-cmd.py b/cmd/save-cmd.py index 366f031..3e7b683 100755 --- a/cmd/save-cmd.py +++ b/cmd/save-cmd.py @@ -395,18 +395,13 @@ for (transname,ent) in r.filter(extra, wantrecurse=wantrecurse_during): else: if stat.S_ISREG(ent.mode): try: - f = hashsplit.open_noatime(ent.name) - except (IOError, OSError) as e: - add_error(e) - lastskip_name = ent.name - else: - try: + with hashsplit.open_noatime(ent.name) as f: (mode, id) = hashsplit.split_to_blob_or_tree( w.new_blob, w.new_tree, [f], keep_boundaries=False) - except (IOError, OSError) as e: - add_error('%s: %s' % (ent.name, e)) - lastskip_name = ent.name + except (IOError, OSError) as e: + add_error('%s: %s' % (ent.name, e)) + lastskip_name = ent.name else: if stat.S_ISDIR(ent.mode): assert(0) # handled above