You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by tv...@apache.org on 2021/02/04 07:48:54 UTC

[buildstream] 09/10: WIP: cascache.py: Add contains_directory_and_blobs() method

This is an automated email from the ASF dual-hosted git repository.

tvb pushed a commit to branch juerg/public-data
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 2f9acf50abe8f776988ff8d90e90be6e80f866d7
Author: Jürg Billeter <j...@bitron.ch>
AuthorDate: Tue Apr 7 18:26:43 2020 +0200

    WIP: cascache.py: Add contains_directory_and_blobs() method
---
 src/buildstream/_cas/cascache.py | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/src/buildstream/_cas/cascache.py b/src/buildstream/_cas/cascache.py
index 61a1a8f..22f5b7c 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.