]> 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>
Wed, 20 May 2020 06:03:05 +0000 (01:03 -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>
cmd/save-cmd.py

index a6190b0a09623a6654d7e860b3a8405f5df33066..b84d63e1c910eb3112e85c362b3fe1e55ba56889 100755 (executable)
@@ -408,18 +408,13 @@ for (transname,ent) in r.filter(extra, wantrecurse=wantrecurse_during):
         id = None
         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
         elif stat.S_ISDIR(ent.mode):
             assert(0)  # handled above
         elif stat.S_ISLNK(ent.mode):