[Git][reproducible-builds/diffoscope][master] Don't call close_archive when garbage-collecting Archive instances unless...
Chris Lamb (@lamby)
gitlab at salsa.debian.org
Mon Sep 27 13:14:56 UTC 2021
Chris Lamb pushed to branch master at Reproducible Builds / diffoscope
Commits:
9007e009 by Chris Lamb at 2021-09-27T14:14:35+01:00
Don't call close_archive when garbage-collecting Archive instances unless open_archive returned successfully. This prevents, for example, an AttributeError as PGPContainer's cleanup routines was assumed that its temporary directory had been created. (Closes: reproducible-builds/diffoscope#276)
- - - - -
1 changed file:
- diffoscope/comparators/utils/archive.py
Changes:
=====================================
diffoscope/comparators/utils/archive.py
=====================================
@@ -41,10 +41,22 @@ class Archive(Container, metaclass=abc.ABCMeta):
super().__init__(*args, **kwargs)
with profile("open_archive", self):
self._archive = self.open_archive()
+ self._opened = True
def __del__(self):
- with profile("close_archive", self):
- self.close_archive()
+ """
+ __del__ can be called even if __init__ did not fully complete. This
+ becomes an issue if an `open_archive` call fails (due to a faulty
+ archive, missing dependency, etc.), and close_archive then assumes that
+ it was opened successfully.
+
+ We therefore track whether open_archive actually worked, and only call
+ close_archive if that was the case. (#276)
+ """
+
+ if hasattr(self, "_opened"):
+ with profile("close_archive", self):
+ self.close_archive()
@property
def archive(self):
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/commit/9007e0098a4b7567c19a1ad2696db48a0ba153cf
--
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/commit/9007e0098a4b7567c19a1ad2696db48a0ba153cf
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20210927/4fdebd1b/attachment.htm>
More information about the rb-commits
mailing list