Commit db503a42 authored by Jürg Billeter's avatar Jürg Billeter

_artifactcache: Add bool return value to pull()

Calling pull() for a potentially unavailable artifact is no longer
considered an error.
parent 4e512529
......@@ -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__))
......
......@@ -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
......@@ -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()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment