]> arthur.barton.de Git - bup.git/commitdiff
save: close files immediately
authorJohannes Berg <johannes@sipsolutions.net>
Sat, 16 May 2020 07:03:31 +0000 (09:03 +0200)
committerRob Browning <rlb@defaultvalue.org>
Sat, 23 May 2020 16:54:54 +0000 (11:54 -0500)
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 <johannes@sipsolutions.net>
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
(cherry picked from commit 0c009932e7eae09badf847b951025f2bad4c271f)
[rlb@defaultvalue.org: adjusted for 0.30.x]

cmd/save-cmd.py

index 366f031cab1011cbd3c520e9929d80e01f514485..3e7b683e3a77ab225f8af0a7f44b913cede747e8 100755 (executable)
@@ -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