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.
This commit is contained in:
parent
72d83a6f94
commit
e24e71be6a
@ -5,6 +5,7 @@
|
||||
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
from itertools import product
|
||||
|
||||
from spack.util.executable import which
|
||||
@ -18,6 +19,8 @@
|
||||
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):
|
||||
|
Loading…
Reference in New Issue
Block a user