Skip to content
Snippets Groups Projects
Commit a98f743a authored by Chris Lamb's avatar Chris Lamb :eyes:
Browse files

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