From bed4b171077058f1ed29785c6def52de2b1f441c Mon Sep 17 00:00:00 2001 From: Andrew Pantuso Date: Sun, 25 Jul 2021 11:29:30 -0400 Subject: [PATCH] Comparing with tar file checksums rather than tar header checksums --- plugins/modules/files/archive.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/plugins/modules/files/archive.py b/plugins/modules/files/archive.py index 3a147f03a2..46f583c5e5 100644 --- a/plugins/modules/files/archive.py +++ b/plugins/modules/files/archive.py @@ -247,6 +247,20 @@ def strip_prefix(prefix, 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): return to_bytes(s, errors='surrogate_or_strict') @@ -585,11 +599,11 @@ class TarArchive(Archive): if self.format == 'xz': with lzma.open(_to_native_ascii(path), 'r') as f: archive = tarfile.open(fileobj=f) - checksums = set((info.name, info.chksum) for info in archive.getmembers()) + checksums = set(tar_checksums(archive)) archive.close() else: 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() except (lzma.LZMAError, tarfile.ReadError, tarfile.CompressionError): try: