From 0c009932e7eae09badf847b951025f2bad4c271f Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sat, 16 May 2020 09:03:31 +0200 Subject: [PATCH] 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 --- cmd/save-cmd.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/cmd/save-cmd.py b/cmd/save-cmd.py index a6190b0..b84d63e 100755 --- a/cmd/save-cmd.py +++ b/cmd/save-cmd.py @@ -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): -- 2.39.2