summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/spack/spack/__init__.py2
-rw-r--r--lib/spack/spack/fetch_strategy.py19
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."""