From 9e7fe04a77de700f11c55a215108f7d595532cb9 Mon Sep 17 00:00:00 2001 From: Dan Lipsa Date: Fri, 8 Sep 2023 13:27:43 -0400 Subject: [PATCH] Windows decompression: fix removal of intermediate file (#38958) Extensionless archives requiring two-stage decompression and extraction require intermediate archives to be renamed after decompression/extraction to prevent collision. Prior behavior attempted to cleanup the intermediate archive with the original name, this PR ensures the renamed folder is cleaned instead. Co-authored-by: Dan Lipsa Co-authored-by: John Parent --- lib/spack/spack/util/compression.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/spack/spack/util/compression.py b/lib/spack/spack/util/compression.py index fd8d17edb8..b8dcd032f4 100644 --- a/lib/spack/spack/util/compression.py +++ b/lib/spack/spack/util/compression.py @@ -70,7 +70,7 @@ def allowed_archive(path): return False if not path else any(path.endswith(t) for t in ALLOWED_ARCHIVE_TYPES) -def _system_untar(archive_file): +def _system_untar(archive_file, remove_archive_file=False): """Returns path to unarchived tar file. Untars archive via system tar. @@ -89,6 +89,11 @@ def _system_untar(archive_file): tar = which("tar", required=True) tar.add_default_arg("-oxf") tar(archive_file) + if remove_archive_file: + # remove input file to prevent two stage + # extractions from being treated as exploding + # archives by the fetcher + os.remove(archive_file) return outfile @@ -243,13 +248,9 @@ def _win_compressed_tarball_handler(decompressor): def unarchive(archive_file): # perform intermediate extraction step # record name of new archive so we can extract - # and later clean up decomped_tarball = decompressor(archive_file) # run tar on newly decomped archive - outfile = _system_untar(decomped_tarball) - # clean intermediate archive to mimic end result - # produced by one shot decomp/extraction - os.remove(decomped_tarball) + outfile = _system_untar(decomped_tarball, remove_archive_file=True) return outfile return unarchive