From: Johannes Berg Date: Sat, 16 May 2020 07:03:31 +0000 (+0200) Subject: save: close files immediately X-Git-Tag: 0.31~75 X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=bup.git;a=commitdiff_plain;h=0c009932e7eae09badf847b951025f2bad4c271f;ds=sidebyside 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 --- 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):