1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Comparing with tar file checksums rather than tar header checksums

This commit is contained in:
Andrew Pantuso 2021-07-25 11:29:30 -04:00
parent 26fdd30542
commit bed4b17107

View file

@ -247,6 +247,20 @@ def strip_prefix(prefix, string):
return string[len(prefix):] if string.startswith(prefix) else string return string[len(prefix):] if string.startswith(prefix) else string
def tar_checksums(tar):
result = []
while True:
info = tar.next()
if info is None:
break
f = tar.extractfile(info)
result += (info.name, crc32(f.read()) if f is not None else 0)
return result
def _to_bytes(s): def _to_bytes(s):
return to_bytes(s, errors='surrogate_or_strict') return to_bytes(s, errors='surrogate_or_strict')
@ -585,11 +599,11 @@ class TarArchive(Archive):
if self.format == 'xz': if self.format == 'xz':
with lzma.open(_to_native_ascii(path), 'r') as f: with lzma.open(_to_native_ascii(path), 'r') as f:
archive = tarfile.open(fileobj=f) archive = tarfile.open(fileobj=f)
checksums = set((info.name, info.chksum) for info in archive.getmembers()) checksums = set(tar_checksums(archive))
archive.close() archive.close()
else: else:
archive = tarfile.open(_to_native_ascii(path), 'r|' + self.format) archive = tarfile.open(_to_native_ascii(path), 'r|' + self.format)
checksums = set((info.name, info.chksum) for info in archive.getmembers()) checksums = set(tar_checksums(archive))
archive.close() archive.close()
except (lzma.LZMAError, tarfile.ReadError, tarfile.CompressionError): except (lzma.LZMAError, tarfile.ReadError, tarfile.CompressionError):
try: try: