From 3b78d933cf46d5cad8f90ea6cdf38ada9e10846f Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Fri, 21 Sep 2018 15:55:09 -0400 Subject: [PATCH] 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. --- beets/importer.py | 4 ++-- docs/changelog.rst | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/beets/importer.py b/beets/importer.py index 4e4084eec..889f1297e 100644 --- a/beets/importer.py +++ b/beets/importer.py @@ -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() diff --git a/docs/changelog.rst b/docs/changelog.rst index b0e7a6cab..2d456ae88 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -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