Skip to content
Snippets Groups Projects
Commit 9007e009 authored by Chris Lamb's avatar Chris Lamb :eyes:
Browse files

Don't call close_archive when garbage-collecting Archive instances unless...

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: #276)
parent fa530947
No related branches found
No related tags found
No related merge requests found
Pipeline #296280 passed
......@@ -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):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment