Skip to content

Commit

Permalink
do not fail when only listing password-protected archives
Browse files Browse the repository at this point in the history
  • Loading branch information
huettenhain committed Dec 3, 2024
1 parent 86bd910 commit 3204b47
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
5 changes: 4 additions & 1 deletion refinery/units/formats/archive/xt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 12 additions & 4 deletions refinery/units/formats/archive/xt7z.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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:
Expand All @@ -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.')

Expand All @@ -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:
Expand Down

0 comments on commit 3204b47

Please sign in to comment.