Commit a98f743a authored by Chris Lamb's avatar Chris Lamb 💬

Factor out the ability to ignore the exit codes of "zipinfo" and "zipinfo -v"...

Factor out the ability to ignore the exit codes of "zipinfo" and "zipinfo -v" in the presence of non-standard headers. (re. #60)
parent efd5f959
......@@ -165,14 +165,17 @@ class ZipFile(File):
r'^(Zip archive|Java archive|EPUB document|OpenDocument (Text|Spreadsheet|Presentation|Drawing|Formula|Template|Text Template)|Google Chrome extension)\b'
ZIPINFO = Zipinfo
def compare_details(self, other, source=None):
differences = []
zipinfo_difference = None
if Config().exclude_directory_metadata != 'recursive':
zipinfo_difference = (
Difference.from_command(Zipinfo, self.path, other.path)
Difference.from_command(self.ZIPINFO, self.path, other.path)
or Difference.from_command(
ZipinfoVerbose, self.path, other.path
self.ZIPINFO_VERBOSE, self.path, other.path
or Difference.from_command(
BsdtarVerbose, self.path, other.path
......@@ -187,19 +190,20 @@ class ZipFile(File):
return differences
class MozillaZipCommandMixin(object):
class IgnoreReturncodeMixin(object):
def returncode(self):
# zipinfo emits an error when reading Mozilla-optimized ZIPs,
# which is fine to ignore.
# zipinfo returns with an exit code of 1 when reading Mozilla-optimized
# or Java "jmod" ZIPs as they have non-standard headers which are fine
# to ignore.
return 0
class MozillaZipinfo(MozillaZipCommandMixin, Zipinfo):
class IgnoreReturncodeZipinfo(IgnoreReturncodeMixin, Zipinfo):
class MozillaZipinfoVerbose(MozillaZipCommandMixin, ZipinfoVerbose):
class IgnoreReturncodeZipinfoVerbose(IgnoreReturncodeMixin, ZipinfoVerbose):
......@@ -223,9 +227,12 @@ class MozillaZipContainer(ZipContainer):
return result
class MozillaZipFile(File):
class MozillaZipFile(ZipFile):
CONTAINER_CLASS = MozillaZipContainer
ZIPINFO = IgnoreReturncodeZipinfo
ZIPINFO_VERBOSE = IgnoreReturncodeZipinfoVerbose
def recognizes(cls, file):
# Mozilla-optimized ZIPs start with a 32-bit little endian integer
......@@ -233,14 +240,3 @@ class MozillaZipFile(File):
# central directory (with a PK\x01\x02 signature)
return file.file_header[4:8] == b'PK\x01\x02'
def compare_details(self, other, source=None):
if Config().exclude_directory_metadata == 'recursive':
return []
zipinfo_difference = (
Difference.from_command(MozillaZipinfo, self.path, other.path)
or Difference.from_command(
MozillaZipinfoVerbose, self.path, other.path
or Difference.from_command(BsdtarVerbose, self.path, other.path)
return [zipinfo_difference]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment