Move the self.file guard inside the contextmanager.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
[rlb@defaultvalue.org: split from larger commit; adjust commit message]
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
def _end(self, run_midx=True, abort=False):
# Ignores run_midx during abort
def _end(self, run_midx=True, abort=False):
# Ignores run_midx during abort
- if not self.file:
- return None
+ self.parentfd, pfd, = None, self.parentfd
self.file, f = None, self.file
self.idx, idx = None, self.idx
self.file, f = None, self.file
self.idx, idx = None, self.idx
- self.parentfd, pfd, = None, self.parentfd
-
try:
with nullcontext_if_not(self.objcache), \
finalized(pfd, lambda x: x is not None and os.close(x)), \
try:
with nullcontext_if_not(self.objcache), \
finalized(pfd, lambda x: x is not None and os.close(x)), \
+ nullcontext_if_not(f):
+ if not f:
+ return None
if abort:
os.unlink(self.filename + b'.pack')
if abort:
os.unlink(self.filename + b'.pack')