Do not crash when lzma is not around. (#5393) (#5397)

(cherry picked from commit 5aa1e58749)

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
patchback[bot] 2022-10-20 20:45:27 +02:00 committed by GitHub
parent ec11d13825
commit 1b78f18bf4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 10 deletions

View file

@ -581,6 +581,11 @@ class TarArchive(Archive):
self.file.add(path, archive_name, recursive=False, exclude=py26_filter)
def _get_checksums(self, path):
if HAS_LZMA:
LZMAError = lzma.LZMAError
else:
# Just picking another exception that's also listed below
LZMAError = tarfile.ReadError
try:
if self.format == 'xz':
with lzma.open(_to_native_ascii(path), 'r') as f:
@ -591,7 +596,7 @@ class TarArchive(Archive):
archive = tarfile.open(_to_native_ascii(path), 'r|' + self.format)
checksums = set((info.name, info.chksum) for info in archive.getmembers())
archive.close()
except (lzma.LZMAError, tarfile.ReadError, tarfile.CompressionError):
except (LZMAError, tarfile.ReadError, tarfile.CompressionError):
try:
# The python implementations of gzip, bz2, and lzma do not support restoring compressed files
# to their original names so only file checksum is returned