diff options
author | Jürg Billeter <j@bitron.ch> | 2019-03-12 13:27:33 +0000 |
---|---|---|
committer | Jürg Billeter <j@bitron.ch> | 2019-03-25 10:24:41 +0100 |
commit | 36f032ce1c7bd67865751d0323837b7276377b62 (patch) | |
tree | a7cc98c8ed92f754b6ee29faf4dae4947b62016c | |
parent | 34692a65b2657ec2ffcf721891498da31f65c2de (diff) | |
download | buildstream-36f032ce1c7bd67865751d0323837b7276377b62.tar.gz |
_artifact.py: Expand cached() to check artifact contents
Check whether artifact contents are available instead of only checking
the artifact ref. This is in preparation for partial CAS support.
-rw-r--r-- | buildstream/_artifact.py | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/buildstream/_artifact.py b/buildstream/_artifact.py index a2ec4aeb6..e812aa1a7 100644 --- a/buildstream/_artifact.py +++ b/buildstream/_artifact.py @@ -33,6 +33,7 @@ import shutil from . import _yaml from . import Scope +from ._exceptions import ArtifactError from .types import _KeyStrength from .storage._casbaseddirectory import CasBasedDirectory @@ -446,9 +447,34 @@ class Artifact(): # (bool): Whether artifact is in local cache # def cached(self, key): - element = self._element + context = self._context + + try: + vdir, _ = self._get_directory(key) + except ArtifactError: + # Either ref or top-level artifact directory missing + return False + + # Check whether all metadata is available + metadigest = vdir._get_child_digest('meta') + if not self._artifacts.cas.contains_directory(metadigest, with_files=True): + return False + + # Additional checks only relevant if artifact was created with 'files' subdirectory + if vdir._exists('files'): + # Determine whether directories are required + require_directories = context.require_artifact_directories + # Determine whether file contents are required as well + require_files = context.require_artifact_files + + filesdigest = vdir._get_child_digest('files') - return self._artifacts.contains(element, key) + # Check whether 'files' subdirectory is available, with or without file contents + if (require_directories and + not self._artifacts.cas.contains_directory(filesdigest, with_files=require_files)): + return False + + return True # _get_directory(): # |