(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.

This commit is contained in:
Peter Scheibel 2016-03-18 15:50:24 -07:00
parent 741bea032c
commit 16fa40b893
2 changed files with 21 additions and 0 deletions

View File

@ -46,6 +46,8 @@
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")

View File

@ -156,6 +156,11 @@ def fetch(self):
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 @@ def fetch(self):
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 @@ def check(self):
"%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."""