From: Johannes Berg Date: Sun, 5 Dec 2021 20:19:52 +0000 (+0100) Subject: PackWriter._end: always try to release objcache and parentfd X-Git-Url: https://arthur.ath.cx/gitweb/?a=commitdiff_plain;h=df6c10064ca8b30736fea347fca76cd7ca88f306;p=bup.git PackWriter._end: always try to release objcache and parentfd Move the self.file guard inside the contextmanager. Signed-off-by: Johannes Berg Reviewed-by: Rob Browning [rlb@defaultvalue.org: split from larger commit; adjust commit message] Signed-off-by: Rob Browning Tested-by: Rob Browning --- diff --git a/lib/bup/git.py b/lib/bup/git.py index 26bdf6d..270f1eb 100644 --- a/lib/bup/git.py +++ b/lib/bup/git.py @@ -918,16 +918,15 @@ class PackWriter(object): 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.parentfd, pfd, = None, self.parentfd - try: with nullcontext_if_not(self.objcache), \ finalized(pfd, lambda x: x is not None and os.close(x)), \ - f: + nullcontext_if_not(f): + if not f: + return None if abort: os.unlink(self.filename + b'.pack')