summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2018-04-19 08:44:27 +0200
committerJürg Billeter <j@bitron.ch>2018-05-11 07:57:37 +0200
commitdb503a42f2fb6d84d8254e09bcea308b601952ea (patch)
tree7e2e37d3e8c7f676db0c0ab8a5ccb80bd81b4177
parent4e5125299ca04d3b3ad01af0653e7e45800e3cfa (diff)
downloadbuildstream-db503a42f2fb6d84d8254e09bcea308b601952ea.tar.gz
_artifactcache: Add bool return value to pull()
Calling pull() for a potentially unavailable artifact is no longer considered an error.
-rw-r--r--buildstream/_artifactcache/artifactcache.py3
-rw-r--r--buildstream/_artifactcache/ostreecache.py10
-rw-r--r--buildstream/element.py4
3 files changed, 11 insertions, 6 deletions
diff --git a/buildstream/_artifactcache/artifactcache.py b/buildstream/_artifactcache/artifactcache.py
index 352cdb4a9..18fca86e0 100644
--- a/buildstream/_artifactcache/artifactcache.py
+++ b/buildstream/_artifactcache/artifactcache.py
@@ -333,6 +333,9 @@ class ArtifactCache():
# key (str): The cache key to use
# progress (callable): The progress callback, if any
#
+ # Returns:
+ # (bool): True if pull was successful, False if artifact was not available
+ #
def pull(self, element, key, *, progress=None):
raise ImplError("Cache '{kind}' does not implement pull()"
.format(kind=type(self).__name__))
diff --git a/buildstream/_artifactcache/ostreecache.py b/buildstream/_artifactcache/ostreecache.py
index 97e9088a5..b592ac4f2 100644
--- a/buildstream/_artifactcache/ostreecache.py
+++ b/buildstream/_artifactcache/ostreecache.py
@@ -171,9 +171,14 @@ class OSTreeCache(ArtifactCache):
try:
# fetch the artifact from highest priority remote using the specified cache key
- remote = artifact_map.lookup_first(ref)
+ remotes = artifact_map.lookup(ref)
+ if not remotes:
+ return False
+
+ remote = remotes[0]
remote_name = self._ensure_remote(self.repo, remote.pull_url)
_ostree.fetch(self.repo, remote=remote_name, ref=ref, progress=progress)
+ return True
except OSTreeError as e:
raise ArtifactError("Failed to pull artifact for element {}: {}"
.format(element.name, e)) from e
@@ -429,8 +434,5 @@ class _OSTreeArtifactMap():
def lookup(self, ref):
return self._ref_to_remotes.get(ref, [])
- def lookup_first(self, ref):
- return self._ref_to_remotes.get(ref, [])[0]
-
def contains(self, ref):
return ref in self._ref_to_remotes
diff --git a/buildstream/element.py b/buildstream/element.py
index c563b79af..adcccc8cf 100644
--- a/buildstream/element.py
+++ b/buildstream/element.py
@@ -1569,12 +1569,12 @@ class Element(Plugin):
if self.__remotely_strong_cached:
key = self.__strict_cache_key
- self.__artifacts.pull(self, key, progress=progress)
+ assert self.__artifacts.pull(self, key, progress=progress)
# update weak ref by pointing it to this newly fetched artifact
self.__artifacts.link_key(self, key, weak_key)
elif not context.get_strict() and self.__remotely_cached:
- self.__artifacts.pull(self, weak_key, progress=progress)
+ assert self.__artifacts.pull(self, weak_key, progress=progress)
# extract strong cache key from this newly fetched artifact
self._update_state()