summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJohn W. Parent <45471568+johnwparent@users.noreply.github.com>2022-05-13 16:38:05 -0400
committerGitHub <noreply@github.com>2022-05-13 13:38:05 -0700
commite24e71be6aec4e83b2d7a9023068cab377132bbe (patch)
tree02a687393f51f507925441a92d9eb294d5ecb75f /lib
parent72d83a6f9458d6a99f78694ca92aac5ee5cf49af (diff)
downloadspack-e24e71be6aec4e83b2d7a9023068cab377132bbe.tar.gz
spack-e24e71be6aec4e83b2d7a9023068cab377132bbe.tar.bz2
spack-e24e71be6aec4e83b2d7a9023068cab377132bbe.tar.xz
spack-e24e71be6aec4e83b2d7a9023068cab377132bbe.zip
Preserve Permissions on .zip extraction (#30407)
#24556 merged in support for Python's .zip file support via ZipFile. However as per #30200 ZipFile does not preserve file permissions of the extracted contents. This PR returns to using the `unzip` executable on non-Windows systems (as was the case before #24556) and now uses `tar` on Windows to extract .zip files.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/util/compression.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/spack/spack/util/compression.py b/lib/spack/spack/util/compression.py
index 60b43e34ce..a5b7db4ec2 100644
--- a/lib/spack/spack/util/compression.py
+++ b/lib/spack/spack/util/compression.py
@@ -5,6 +5,7 @@
import os
import re
+import sys
from itertools import product
from spack.util.executable import which
@@ -18,6 +19,8 @@ NOTAR_EXTS = ["zip", "tgz", "tbz", "tbz2", "txz"]
ALLOWED_ARCHIVE_TYPES = [".".join(ext) for ext in product(
PRE_EXTS, EXTS)] + PRE_EXTS + EXTS + NOTAR_EXTS
+is_windows = sys.platform == 'win32'
+
def allowed_archive(path):
return any(path.endswith(t) for t in ALLOWED_ARCHIVE_TYPES)
@@ -48,15 +51,14 @@ def _unzip(archive_file):
Args:
archive_file (str): absolute path of the file to be decompressed
"""
- try:
- from zipfile import ZipFile
- destination_abspath = os.getcwd()
- with ZipFile(archive_file, 'r') as zf:
- zf.extractall(destination_abspath)
- except ImportError:
- unzip = which('unzip', required=True)
- unzip.add_default_arg('-q')
- return unzip
+ exe = 'unzip'
+ arg = '-q'
+ if is_windows:
+ exe = 'tar'
+ arg = '-xf'
+ unzip = which(exe, required=True)
+ unzip.add_default_arg(arg)
+ unzip(archive_file)
def decompressor_for(path, extension=None):