summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan Lipsa <dan.lipsa@kitware.com>2023-09-08 13:27:43 -0400
committerGitHub <noreply@github.com>2023-09-08 10:27:43 -0700
commit9e7fe04a77de700f11c55a215108f7d595532cb9 (patch)
tree003a00bfce6ba7c280b6c1aa93d6bfc6d9fc62f3 /lib
parent45d149c7d32b616ddf9f1a503506fa22012a10b4 (diff)
downloadspack-9e7fe04a77de700f11c55a215108f7d595532cb9.tar.gz
spack-9e7fe04a77de700f11c55a215108f7d595532cb9.tar.bz2
spack-9e7fe04a77de700f11c55a215108f7d595532cb9.tar.xz
spack-9e7fe04a77de700f11c55a215108f7d595532cb9.zip
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 <dan.lipsa@khq.kitware.com> Co-authored-by: John Parent <john.parent@kitware.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/util/compression.py13
1 files 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