Fix #3041: only try to close opened archives

The "finally" clause here only wants to apply when `archive` is
assigned. Otherwise, we were getting a NameError trying to refer to the
appropriate variable.
This commit is contained in:
Adrian Sampson 2018-09-21 15:55:09 -04:00
parent 6a92fa8b70
commit 3b78d933cf
2 changed files with 4 additions and 2 deletions

View file

@ -1059,9 +1059,9 @@ class ArchiveImportTask(SentinelImportTask):
if path_test(util.py3_path(self.toppath)):
break
extract_to = mkdtemp()
archive = handler_class(util.py3_path(self.toppath), mode='r')
try:
extract_to = mkdtemp()
archive = handler_class(util.py3_path(self.toppath), mode='r')
archive.extractall(extract_to)
finally:
archive.close()

View file

@ -86,6 +86,8 @@ Fixes:
* Fix a problem when resizing images with PIL/Pillow on Python 3.
Thanks to :user:`architek`.
:bug:`2504` :bug:`3029`
* Avoid a crash when archive extraction fails during import.
:bug:`3041`
.. _python-itunes: https://github.com/ocelma/python-itunes