pursuing a strategy using fetch.archive and treating var/spack/cache as a mirror. this should support both URLFetchStrategy as well as VCSFetchStrategy (the previous strategy supported only the former). this won't work until URLFetchStrategy.archive is updated

This commit is contained in:
Peter Scheibel 2016-03-21 20:48:12 -07:00
parent d632266a40
commit ee5e507ff6
3 changed files with 14 additions and 18 deletions

View File

@ -156,11 +156,6 @@ def fetch(self):
if self.archive_file: if self.archive_file:
tty.msg("Already downloaded %s" % self.archive_file) tty.msg("Already downloaded %s" % self.archive_file)
return return
cached = self.search_cache()
if cached:
tty.msg("Cached %s." % cached)
shutil.copy(cached, "./")
return
tty.msg("Trying to fetch from %s" % self.url) tty.msg("Trying to fetch from %s" % self.url)
@ -216,8 +211,6 @@ def fetch(self):
if not self.archive_file: if not self.archive_file:
raise FailedDownloadError(self.url) raise FailedDownloadError(self.url)
elif self.digest:
shutil.copy(self.archive_file, spack.cache_path)
@property @property
@ -292,16 +285,6 @@ def check(self):
"Expected %s but got %s" % (self.digest, checker.sum)) "Expected %s but got %s" % (self.digest, checker.sum))
def search_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 @_needs_stage
def reset(self): def reset(self):
"""Removes the source path if it exists, then re-expands the archive.""" """Removes the source path if it exists, then re-expands the archive."""

View File

@ -715,6 +715,8 @@ def do_fetch(self, mirror_only=False):
if spack.do_checksum and self.version in self.versions: if spack.do_checksum and self.version in self.versions:
self.stage.check() self.stage.check()
self.stage.cache_local()
def do_stage(self, mirror_only=False): def do_stage(self, mirror_only=False):
"""Unpacks the fetched tarball, then changes into the expanded tarball """Unpacks the fetched tarball, then changes into the expanded tarball

View File

@ -273,6 +273,7 @@ def fetch(self, mirror_only=False):
# the root, so we add a '/' if it is not present. # the root, so we add a '/' if it is not present.
mirror_roots = [root if root.endswith('/') else root + '/' mirror_roots = [root if root.endswith('/') else root + '/'
for root in mirrors.values()] for root in mirrors.values()]
mirror_roots.append("file://" + os.path.abspath(spack.cache_path) + os.sep)
urls = [urljoin(root, self.mirror_path) for root in mirror_roots] urls = [urljoin(root, self.mirror_path) for root in mirror_roots]
# If this archive is normally fetched from a tarball URL, # If this archive is normally fetched from a tarball URL,
@ -305,6 +306,7 @@ def fetch(self, mirror_only=False):
self.fetcher = self.default_fetcher self.fetcher = self.default_fetcher
raise fs.FetchError(errMessage, None) raise fs.FetchError(errMessage, None)
def check(self): def check(self):
"""Check the downloaded archive against a checksum digest. """Check the downloaded archive against a checksum digest.
No-op if this stage checks code out of a repository.""" No-op if this stage checks code out of a repository."""
@ -318,6 +320,15 @@ def check(self):
else: else:
self.fetcher.check() self.fetcher.check()
def cache_local(self):
archiveDst = join_path(os.path.abspath(spack.cache_path), self.mirror_path)
mkdirp(os.path.dirname(archiveDst))
# TODO: this moves the archive for URLFetchStrategy vs. a copy - edit
# to do a move?
self.fetcher.archive(archiveDst)
def expand_archive(self): def expand_archive(self):
"""Changes to the stage directory and attempt to expand the downloaded """Changes to the stage directory and attempt to expand the downloaded
archive. Fail if the stage is not set up or if the archive is not yet archive. Fail if the stage is not set up or if the archive is not yet
@ -421,7 +432,7 @@ def expand_archive(self):
shutil.move(source_path, destination_path) shutil.move(source_path, destination_path)
@pattern.composite(method_list=['fetch', 'create', 'check', 'expand_archive', 'restage', 'destroy']) @pattern.composite(method_list=['fetch', 'create', 'check', 'expand_archive', 'restage', 'destroy', 'cache_local'])
class StageComposite: class StageComposite:
""" """
Composite for Stage type objects. The first item in this composite is considered to be the root package, and Composite for Stage type objects. The first item in this composite is considered to be the root package, and