summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2020-04-07 18:26:43 +0200
committerJürg Billeter <j@bitron.ch>2020-04-07 18:27:19 +0200
commit2f9acf50abe8f776988ff8d90e90be6e80f866d7 (patch)
tree18a40ba2dd77b60e02bd3d9d874a4ac3e7d70167
parentffa36b46e1218d1dea845b6208cd63fb11d0cf88 (diff)
downloadbuildstream-2f9acf50abe8f776988ff8d90e90be6e80f866d7.tar.gz
WIP: cascache.py: Add contains_directory_and_blobs() method
-rw-r--r--src/buildstream/_cas/cascache.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/buildstream/_cas/cascache.py b/src/buildstream/_cas/cascache.py
index 61a1a8f50..22f5b7c2f 100644
--- a/src/buildstream/_cas/cascache.py
+++ b/src/buildstream/_cas/cascache.py
@@ -211,6 +211,41 @@ class CASCache:
raise CASCacheError("Unsupported buildbox-casd version: FetchTree unimplemented") from e
raise
+ def contains_directory_and_blobs(self, directory, blobs, *, with_files):
+ cas = self.get_cas()
+ local_cas = self.get_local_cas()
+
+ if str(directory):
+ request = local_cas_pb2.FetchTreeRequest()
+ request.root_digest.CopyFrom(directory)
+ request.fetch_file_blobs = with_files
+ directory_future = local_cas.FetchTree.future(request)
+ else:
+ directory_future = None
+
+ if blobs:
+ request = remote_execution_pb2.FindMissingBlobsRequest()
+ request.blob_digests.extend(blobs)
+ blobs_future = cas.FindMissingBlobs.future(request)
+ else:
+ blobs_future = None
+
+ try:
+ if directory_future:
+ directory_future.result()
+
+ if blobs_future:
+ response = blobs_future.result()
+ return len(response.missing_blob_digests) == 0
+ else:
+ return True
+ 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():
#
# Checkout the specified directory digest.