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>
id = None
if stat.S_ISREG(ent.mode):
try:
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)
(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):
elif stat.S_ISDIR(ent.mode):
assert(0) # handled above
elif stat.S_ISLNK(ent.mode):