summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2018-01-22 17:40:56 +0000
committerSam Thursfield <sam.thursfield@codethink.co.uk>2018-01-22 17:56:11 +0000
commit35acdfa526ae1ae3d004295fdffbabd3f3b95750 (patch)
tree55114d05477480aeebf7893cde4a506a6d45f274
parent6eff8f0d0d94c96060d5565425d8c1cfeacde9fe (diff)
downloadbuildstream-sam/fix-202.tar.gz
_artifactcache/ostreecache.py: Fix pulling using weak keysam/fix-202
It should be possible to pull an artifact knowing only its weak key. However, the pull() and extract() methods would call the `buildref()` helper function asking for the strong cache key and that would then raise a 'Cache key missing' error if we didn't know the strong key.
-rw-r--r--buildstream/_artifactcache/ostreecache.py24
1 files changed, 15 insertions, 9 deletions
diff --git a/buildstream/_artifactcache/ostreecache.py b/buildstream/_artifactcache/ostreecache.py
index d0508bd93..09eb03b2d 100644
--- a/buildstream/_artifactcache/ostreecache.py
+++ b/buildstream/_artifactcache/ostreecache.py
@@ -172,14 +172,16 @@ class OSTreeCache(ArtifactCache):
# Returns: path to extracted artifact
#
def extract(self, element):
- ref = buildref(element, element._get_strict_cache_key())
+ strict_cache_key = element._get_strict_cache_key()
- # resolve ref to checksum
- rev = _ostree.checksum(self.repo, ref)
+ if strict_cache_key:
+ ref = buildref(element, strict_cache_key)
- # resolve weak cache key, if artifact is missing for strong cache key
- # and the context allows use of weak cache keys
- if not rev and not element._get_strict():
+ # resolve ref to checksum
+ rev = _ostree.checksum(self.repo, ref)
+ elif not element._get_strict():
+ # resolve weak cache key, if artifact is missing for strong cache key
+ # and the context allows use of weak cache keys
ref = buildref(element, element._get_cache_key(strength=_KeyStrength.WEAK))
rev = _ostree.checksum(self.repo, ref)
@@ -242,12 +244,16 @@ class OSTreeCache(ArtifactCache):
# progress (callable): The progress callback, if any
#
def pull(self, element, progress=None):
-
- ref = buildref(element, element._get_strict_cache_key())
weak_ref = buildref(element, element._get_cache_key(strength=_KeyStrength.WEAK))
+ strict_cache_key = element._get_strict_cache_key()
+ if strict_cache_key:
+ ref = buildref(element, strict_cache_key)
+ else:
+ ref = None
+
try:
- if ref in self._remote_refs:
+ if ref is not None and ref in self._remote_refs:
# fetch the artifact using the strong cache key
_ostree.fetch(self.repo, remote=self._remote_refs[ref],
ref=ref, progress=progress)