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 os
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
from itertools import product
|
from itertools import product
|
||||||
|
|
||||||
from spack.util.executable import which
|
from spack.util.executable import which
|
||||||
@ -18,6 +19,8 @@
|
|||||||
ALLOWED_ARCHIVE_TYPES = [".".join(ext) for ext in product(
|
ALLOWED_ARCHIVE_TYPES = [".".join(ext) for ext in product(
|
||||||
PRE_EXTS, EXTS)] + PRE_EXTS + EXTS + NOTAR_EXTS
|
PRE_EXTS, EXTS)] + PRE_EXTS + EXTS + NOTAR_EXTS
|
||||||
|
|
||||||
|
is_windows = sys.platform == 'win32'
|
||||||
|
|
||||||
|
|
||||||
def allowed_archive(path):
|
def allowed_archive(path):
|
||||||
return any(path.endswith(t) for t in ALLOWED_ARCHIVE_TYPES)
|
return any(path.endswith(t) for t in ALLOWED_ARCHIVE_TYPES)
|
||||||
@ -48,15 +51,14 @@ def _unzip(archive_file):
|
|||||||
Args:
|
Args:
|
||||||
archive_file (str): absolute path of the file to be decompressed
|
archive_file (str): absolute path of the file to be decompressed
|
||||||
"""
|
"""
|
||||||
try:
|
exe = 'unzip'
|
||||||
from zipfile import ZipFile
|
arg = '-q'
|
||||||
destination_abspath = os.getcwd()
|
if is_windows:
|
||||||
with ZipFile(archive_file, 'r') as zf:
|
exe = 'tar'
|
||||||
zf.extractall(destination_abspath)
|
arg = '-xf'
|
||||||
except ImportError:
|
unzip = which(exe, required=True)
|
||||||
unzip = which('unzip', required=True)
|
unzip.add_default_arg(arg)
|
||||||
unzip.add_default_arg('-q')
|
unzip(archive_file)
|
||||||
return unzip
|
|
||||||
|
|
||||||
|
|
||||||
def decompressor_for(path, extension=None):
|
def decompressor_for(path, extension=None):
|
||||||
|
Loading…
Reference in New Issue
Block a user