From 7741bfb7d1628d8f2e17284e34cbb8d4a69f3553 Mon Sep 17 00:00:00 2001 From: Peter Scheibel Date: Wed, 13 Jul 2022 14:12:21 -0700 Subject: [PATCH] Decompression: use tar exe vs. built-in Python tarfile support (#31563) Python's built-in tarfile support doesn't address some general cases of malformed tarfiles that are already handled by the system 'tar' utility; until these can be addressed, use that exclusively. --- lib/spack/spack/util/compression.py | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/lib/spack/spack/util/compression.py b/lib/spack/spack/util/compression.py index 859f4faa282..5be3fbf3388 100644 --- a/lib/spack/spack/util/compression.py +++ b/lib/spack/spack/util/compression.py @@ -73,25 +73,10 @@ def _untar(archive_file): """ _, ext = os.path.splitext(archive_file) outfile = os.path.basename(archive_file.strip(ext)) - uncompress_required = 'Z' in ext - lzma_required = 'xz' in ext - lzma_needed_and_not_available = not lzma_support() and lzma_required - if tar_support() and not uncompress_required and\ - not lzma_needed_and_not_available: - import tarfile - # Extract all members but wipe ownership info. This ensures we - # will not attempt to chown the files as superuser. - def filter(tarinfo): - tarinfo.uid = tarinfo.gid = 0 - tarinfo.uname = tarinfo.gname = 'root' - return tarinfo - with tarfile.open(archive_file) as tar: - tar.extractall(members=map(filter, tar.getmembers())) - else: - tar = which('tar', required=True) - tar.add_default_arg('-oxf') - tar(archive_file) + tar = which('tar', required=True) + tar.add_default_arg('-oxf') + tar(archive_file) return outfile