1
0
mirror of synced 2024-11-25 02:34:24 +01:00

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.
This commit is contained in:
Daniel Kahn Gillmor 2018-09-02 08:32:34 -04:00
parent 10d60bd398
commit 915dc634c4

View File

@ -88,6 +88,7 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser):
zipfile.ZipFile(self.output_filename, 'w') as zout: zipfile.ZipFile(self.output_filename, 'w') as zout:
temp_folder = tempfile.mkdtemp() temp_folder = tempfile.mkdtemp()
abort = False
for item in zin.infolist(): for item in zin.infolist():
if item.filename[-1] == '/': # `is_dir` is added in Python3.6 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': if self.unknown_member_policy != 'abort':
logging.warning("Invalid unknown_member_policy %s, " + logging.warning("Invalid unknown_member_policy %s, " +
"treating as 'abort'", self.unknown_member_policy) "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) " + logging.error("In file %s, element %s's format (%s) " +
"isn't supported", "isn't supported",
self.filename, item.filename, mtype) self.filename, item.filename, mtype)
return False abort = True
continue
if tmp_parser: if tmp_parser:
tmp_parser.remove_all() tmp_parser.remove_all()
os.rename(tmp_parser.output_filename, full_path) os.rename(tmp_parser.output_filename, full_path)
@ -139,6 +139,9 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser):
zout.writestr(clean_zinfo, f.read()) zout.writestr(clean_zinfo, f.read())
shutil.rmtree(temp_folder) shutil.rmtree(temp_folder)
if abort:
os.remove(self.output_filename)
return False
return True return True