diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/fetch_strategy.py | 2 | ||||
-rw-r--r-- | lib/spack/spack/util/compression.py | 19 |
2 files changed, 19 insertions, 2 deletions
diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py index ff41c759ea..b5ce8495e3 100644 --- a/lib/spack/spack/fetch_strategy.py +++ b/lib/spack/spack/fetch_strategy.py @@ -467,6 +467,8 @@ class URLFetchStrategy(FetchStrategy): tarball_container = os.path.join(self.stage.path, "spack-expanded-archive") + # Below we assume that the command to decompress expand the + # archive in the current working directory mkdirp(tarball_container) with working_dir(tarball_container): decompress(self.archive_file) diff --git a/lib/spack/spack/util/compression.py b/lib/spack/spack/util/compression.py index 2f190e94e1..a1a0e1d6f3 100644 --- a/lib/spack/spack/util/compression.py +++ b/lib/spack/spack/util/compression.py @@ -22,6 +22,22 @@ def allowed_archive(path): return any(path.endswith(t) for t in ALLOWED_ARCHIVE_TYPES) +def _gunzip(archive_file): + """Like gunzip, but extracts in the current working directory + instead of in-place. + + Args: + archive_file (str): absolute path of the file to be decompressed + """ + import gzip + decompressed_file = os.path.basename(archive_file.strip('.gz')) + working_dir = os.getcwd() + destination_abspath = os.path.join(working_dir, decompressed_file) + with gzip.open(archive_file, "rb") as f_in: + with open(destination_abspath, "wb") as f_out: + f_out.write(f_in.read()) + + def decompressor_for(path, extension=None): """Get the appropriate decompressor for a path.""" if ((extension and re.match(r'\.?zip$', extension)) or @@ -30,8 +46,7 @@ def decompressor_for(path, extension=None): unzip.add_default_arg('-q') return unzip if extension and re.match(r'gz', extension): - gunzip = which('gunzip', required=True) - return gunzip + return _gunzip if extension and re.match(r'bz2', extension): bunzip2 = which('bunzip2', required=True) return bunzip2 |