diff options
author | Peter Scheibel <scheibel1@llnl.gov> | 2016-03-18 15:50:24 -0700 |
---|---|---|
committer | Peter Scheibel <scheibel1@llnl.gov> | 2016-03-18 15:50:24 -0700 |
commit | 16fa40b893054d8bd7f13625f204bf02d74a27b5 (patch) | |
tree | 67cb9fd4f04ebfaac0288ea56e0635589613a729 | |
parent | 741bea032c2d6e1dc8a4227c588743fb58008a1c (diff) | |
download | spack-16fa40b893054d8bd7f13625f204bf02d74a27b5.tar.gz spack-16fa40b893054d8bd7f13625f204bf02d74a27b5.tar.bz2 spack-16fa40b893054d8bd7f13625f204bf02d74a27b5.tar.xz spack-16fa40b893054d8bd7f13625f204bf02d74a27b5.zip |
(1) add a var/cache directory under spack. (2) downloads from URLFetchStrategy check the cache and skip the download if the source is available there.
-rw-r--r-- | lib/spack/spack/__init__.py | 2 | ||||
-rw-r--r-- | lib/spack/spack/fetch_strategy.py | 19 |
2 files changed, 21 insertions, 0 deletions
diff --git a/lib/spack/spack/__init__.py b/lib/spack/spack/__init__.py index 0ba42bbbfc..22436e46c4 100644 --- a/lib/spack/spack/__init__.py +++ b/lib/spack/spack/__init__.py @@ -46,6 +46,8 @@ var_path = join_path(spack_root, "var", "spack") stage_path = join_path(var_path, "stage") repos_path = join_path(var_path, "repos") share_path = join_path(spack_root, "share", "spack") +cache_path = join_path(spack_root, "var", "cache") +mkdirp(cache_path) prefix = spack_root opt_path = join_path(prefix, "opt") diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py index 0d0a7db8a9..3a774a35cd 100644 --- a/lib/spack/spack/fetch_strategy.py +++ b/lib/spack/spack/fetch_strategy.py @@ -156,6 +156,11 @@ class URLFetchStrategy(FetchStrategy): if self.archive_file: tty.msg("Already downloaded %s" % self.archive_file) return + cached = self.check_cache() + if cached: + tty.msg("Cached %s." % cached) + shutil.copy(cached, "./") + return tty.msg("Trying to fetch from %s" % self.url) @@ -211,6 +216,9 @@ class URLFetchStrategy(FetchStrategy): if not self.archive_file: raise FailedDownloadError(self.url) + else: + shutil.copy(self.archive_file, spack.cache_path) + @property def archive_file(self): @@ -283,6 +291,17 @@ class URLFetchStrategy(FetchStrategy): "%s checksum failed for %s" % (checker.hash_name, self.archive_file), "Expected %s but got %s" % (self.digest, checker.sum)) + + def check_cache(self): + if not self.digest: + return + checker = crypto.Checker(self.digest) + paths = (join_path(spack.cache_path, f) for f in os.listdir(spack.cache_path)) + for p in paths: + if checker.check(p): + return p + + @_needs_stage def reset(self): """Removes the source path if it exists, then re-expands the archive.""" |