diff --git a/refinery/units/formats/archive/xt.py b/refinery/units/formats/archive/xt.py index c1a0c1af4..824af8c48 100644 --- a/refinery/units/formats/archive/xt.py +++ b/refinery/units/formats/archive/xt.py @@ -122,8 +122,11 @@ def __iter__(self): self.unit.log_debug('handler construction failed:', error) return try: + test_unpack = not self.unit.args.list for item in unit.unpack(data): - item.get_data() + if test_unpack: + item.get_data() + test_unpack = False yield item except Exception as error: if not self.fallback: diff --git a/refinery/units/formats/archive/xt7z.py b/refinery/units/formats/archive/xt7z.py index 431095757..13d0bfcf0 100644 --- a/refinery/units/formats/archive/xt7z.py +++ b/refinery/units/formats/archive/xt7z.py @@ -41,6 +41,12 @@ def mk7z(**keywords): pwd = self.args.pwd mv = memoryview(data) + def test(archive: SevenZipFile): + if self.args.list: + archive.list() + return False + return archive.testzip() + if pwd: try: archive = mk7z(password=pwd.decode(self.codec)) @@ -51,9 +57,13 @@ def passwords(): yield None yield from self._COMMON_PASSWORDS for pwd in passwords(): + if pwd is None: + self.log_debug(U'trying empty password') + else: + self.log_debug(F'trying password: {pwd}') try: archive = mk7z(password=pwd) - problem = archive.testzip() + problem = test(archive) except self._py7zr.PasswordRequired: problem = True except self._py7zr.UnsupportedCompressionMethodError as E: @@ -69,8 +79,6 @@ def passwords(): problem = True if not problem: break - if pwd is not None: - self.log_debug(F'trying password: {pwd}') else: raise ValueError('a password is required and none of the default passwords worked.') @@ -80,7 +88,7 @@ def extract(archive: SevenZipFile = archive, info: FileInfo = info): return archive.read([info.filename]).get(info.filename).read() if info.is_directory: continue - yield self._pack(info.filename, info.creationtime, extract, crc32=info.crc32) + yield self._pack(info.filename, info.creationtime, extract, crc32=info.crc32, uncompressed=info.uncompressed) @classmethod def handles(cls, data: bytearray) -> bool: