diff options
| author | Daniel Kahn Gillmor | 2018-09-02 08:32:34 -0400 |
|---|---|---|
| committer | Daniel Kahn Gillmor | 2018-09-04 18:28:04 -0400 |
| commit | 915dc634c4fd51e4dda5697cf8fd150cef9d1f3a (patch) | |
| tree | ebaa7c8fefe39a5218597253a580c4f8a478a0c4 /libmat2/office.py | |
| parent | 10d60bd39822670c55b84cb9d13dce8aea78bc40 (diff) | |
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.
Diffstat (limited to 'libmat2/office.py')
| -rw-r--r-- | libmat2/office.py | 9 |
1 files 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): | |||
| 88 | zipfile.ZipFile(self.output_filename, 'w') as zout: | 88 | zipfile.ZipFile(self.output_filename, 'w') as zout: |
| 89 | 89 | ||
| 90 | temp_folder = tempfile.mkdtemp() | 90 | temp_folder = tempfile.mkdtemp() |
| 91 | abort = False | ||
| 91 | 92 | ||
| 92 | for item in zin.infolist(): | 93 | for item in zin.infolist(): |
| 93 | if item.filename[-1] == '/': # `is_dir` is added in Python3.6 | 94 | if item.filename[-1] == '/': # `is_dir` is added in Python3.6 |
| @@ -123,12 +124,11 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser): | |||
| 123 | if self.unknown_member_policy != 'abort': | 124 | if self.unknown_member_policy != 'abort': |
| 124 | logging.warning("Invalid unknown_member_policy %s, " + | 125 | logging.warning("Invalid unknown_member_policy %s, " + |
| 125 | "treating as 'abort'", self.unknown_member_policy) | 126 | "treating as 'abort'", self.unknown_member_policy) |
| 126 | shutil.rmtree(temp_folder) | ||
| 127 | os.remove(self.output_filename) | ||
| 128 | logging.error("In file %s, element %s's format (%s) " + | 127 | logging.error("In file %s, element %s's format (%s) " + |
| 129 | "isn't supported", | 128 | "isn't supported", |
| 130 | self.filename, item.filename, mtype) | 129 | self.filename, item.filename, mtype) |
| 131 | return False | 130 | abort = True |
| 131 | continue | ||
| 132 | if tmp_parser: | 132 | if tmp_parser: |
| 133 | tmp_parser.remove_all() | 133 | tmp_parser.remove_all() |
| 134 | os.rename(tmp_parser.output_filename, full_path) | 134 | os.rename(tmp_parser.output_filename, full_path) |
| @@ -139,6 +139,9 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser): | |||
| 139 | zout.writestr(clean_zinfo, f.read()) | 139 | zout.writestr(clean_zinfo, f.read()) |
| 140 | 140 | ||
| 141 | shutil.rmtree(temp_folder) | 141 | shutil.rmtree(temp_folder) |
| 142 | if abort: | ||
| 143 | os.remove(self.output_filename) | ||
| 144 | return False | ||
| 142 | return True | 145 | return True |
| 143 | 146 | ||
| 144 | 147 | ||
