summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2019-09-24 17:11:46 +0200
committerbst-marge-bot <marge-bot@buildstream.build>2019-10-02 09:26:19 +0000
commit4c57dc0afb87b1f3be1e2abe87063326d27600cd (patch)
tree5187b6f9739ef3dcf453569b1be761402962c447
parent23c66d2bd397b84c8905fa16027e0ba163d1b4cd (diff)
downloadbuildstream-4c57dc0afb87b1f3be1e2abe87063326d27600cd.tar.gz
cascache.py: Add import_directory() method
This allows import of a whole directory tree with a single gRPC call to buildbox-casd CaptureTree() instead of importing files one at a time.
-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 6002adc4a..97ee2edd7 100644
--- a/src/buildstream/_cas/cascache.py
+++ b/src/buildstream/_cas/cascache.py
@@ -421,6 +421,41 @@ class CASCache():
return digest
+ # import_directory():
+ #
+ # Import directory tree into CAS.
+ #
+ # Args:
+ # path (str): Path to directory to import
+ #
+ # Returns:
+ # (Digest): The digest of the imported directory
+ #
+ def import_directory(self, path):
+ local_cas = self._get_local_cas()
+
+ request = local_cas_pb2.CaptureTreeRequest()
+ request.path.append(path)
+ response = local_cas.CaptureTree(request)
+
+ if len(response.responses) != 1:
+ raise CASCacheError("Expected 1 response from CaptureTree, got {}".format(len(response.responses)))
+
+ tree_response = response.responses[0]
+ if tree_response.status.code == code_pb2.RESOURCE_EXHAUSTED:
+ raise CASCacheError("Cache too full", reason="cache-too-full")
+ if tree_response.status.code != code_pb2.OK:
+ raise CASCacheError("Failed to capture tree {}: {}".format(path, tree_response.status.code))
+
+ treepath = self.objpath(tree_response.tree_digest)
+ tree = remote_execution_pb2.Tree()
+ with open(treepath, 'rb') as f:
+ tree.ParseFromString(f.read())
+
+ root_directory = tree.root.SerializeToString()
+
+ return utils._message_digest(root_directory)
+
# set_ref():
#
# Create or replace a ref.