summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2019-10-02 10:17:53 +0100
committerJürg Billeter <j@bitron.ch>2019-11-04 16:52:30 +0100
commit6bc539055ccaa5b89ffb0841006141e5aafe0d0a (patch)
tree64c1ad049c74ff4a6fe8874681b9154a4d94b15d
parenta52e363da4ba46d095a401dcab9633cafff9025d (diff)
downloadbuildstream-juerg/fetch-tree.tar.gz
cascache.py: Reimplement contains_directory() with FetchTree()juerg/fetch-tree
-rw-r--r--src/buildstream/_cas/cascache.py33
1 files changed, 12 insertions, 21 deletions
diff --git a/src/buildstream/_cas/cascache.py b/src/buildstream/_cas/cascache.py
index b2158597e..022730445 100644
--- a/src/buildstream/_cas/cascache.py
+++ b/src/buildstream/_cas/cascache.py
@@ -255,30 +255,21 @@ class CASCache():
# Returns: True if the directory is available in the local cache
#
def contains_directory(self, digest, *, with_files):
- try:
- directory = remote_execution_pb2.Directory()
- path = self.objpath(digest)
- with open(path, 'rb') as f:
- directory.ParseFromString(f.read())
- os.utime(f.fileno())
-
- # Optionally check presence of files
- if with_files:
- for filenode in directory.files:
- path = self.objpath(filenode.digest)
-
- # No need for separate `exists()` call as this will raise
- # FileNotFoundError if the file does not exist.
- os.utime(path)
+ local_cas = self._get_local_cas()
- # Check subdirectories
- for dirnode in directory.directories:
- if not self.contains_directory(dirnode.digest, with_files=with_files):
- return False
+ request = local_cas_pb2.FetchTreeRequest()
+ request.root_digest.CopyFrom(digest)
+ request.fetch_file_blobs = with_files
+ try:
+ local_cas.FetchTree(request)
return True
- except FileNotFoundError:
- return False
+ except grpc.RpcError as e:
+ if e.code() == grpc.StatusCode.NOT_FOUND:
+ return False
+ if e.code() == grpc.StatusCode.UNIMPLEMENTED:
+ raise CASCacheError("Unsupported buildbox-casd version: FetchTree unimplemented") from e
+ raise
# checkout():
#