From 915dc634c4fd51e4dda5697cf8fd150cef9d1f3a Mon Sep 17 00:00:00 2001 From: Daniel Kahn Gillmor <dkg@fifthhorseman.net> Date: Sun, 2 Sep 2018 08:32:34 -0400 Subject: [PATCH] document all unknown/unhandlable files even on abort This makes it easy to get a list of all files that mat2 doesn't know how to handle, without having to choose -u keep or -u omit. --- libmat2/office.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libmat2/office.py b/libmat2/office.py index 23249b4..e48773a 100644 --- a/libmat2/office.py +++ b/libmat2/office.py @@ -88,6 +88,7 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser): zipfile.ZipFile(self.output_filename, 'w') as zout: temp_folder = tempfile.mkdtemp() + abort = False for item in zin.infolist(): if item.filename[-1] == '/': # `is_dir` is added in Python3.6 @@ -123,12 +124,11 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser): if self.unknown_member_policy != 'abort': logging.warning("Invalid unknown_member_policy %s, " + "treating as 'abort'", self.unknown_member_policy) - shutil.rmtree(temp_folder) - os.remove(self.output_filename) logging.error("In file %s, element %s's format (%s) " + "isn't supported", self.filename, item.filename, mtype) - return False + abort = True + continue if tmp_parser: tmp_parser.remove_all() os.rename(tmp_parser.output_filename, full_path) @@ -139,6 +139,9 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser): zout.writestr(clean_zinfo, f.read()) shutil.rmtree(temp_folder) + if abort: + os.remove(self.output_filename) + return False return True -- GitLab