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

akitouni pushed a commit to branch abderrahim/ensure-blobs
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 52992812ed4a621ab60f08a0674e724cf052e293
Author: Abderrahim Kitouni <[email protected]>
AuthorDate: Thu Aug 1 13:23:44 2024 +0100

    cascache: add a helper method to ensure a tree is cached locally
---
 src/buildstream/_cas/cascache.py | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/src/buildstream/_cas/cascache.py b/src/buildstream/_cas/cascache.py
index 627778c16..66d861aec 100644
--- a/src/buildstream/_cas/cascache.py
+++ b/src/buildstream/_cas/cascache.py
@@ -169,15 +169,9 @@ class CASCache:
     #     can_link (bool): Whether we can create hard links in the destination
     #
     def checkout(self, dest, tree, *, can_link=False, _fetch=True):
-        if _fetch and self._remote_cache:
+        if _fetch:
             # We need the files in the local cache
-            local_cas = self.get_local_cas()
-
-            request = local_cas_pb2.FetchTreeRequest()
-            request.root_digest.CopyFrom(tree)
-            request.fetch_file_blobs = True
-
-            local_cas.FetchTree(request)
+            self.ensure_tree(tree)
 
         os.makedirs(dest, exist_ok=True)
 
@@ -223,6 +217,24 @@ class CASCache:
             fullpath = os.path.join(dest, symlinknode.name)
             os.symlink(symlinknode.target, fullpath)
 
+    # ensure_tree():
+    #
+    # Make sure all blobs referenced by the given directory tree are available
+    # in the local cache when using a remote cache.
+    #
+    # Args:
+    #     tree (Digest): The digest of the tree
+    #
+    def ensure_tree(self, tree):
+        if self._remote_cache:
+            local_cas = self.get_local_cas()
+
+            request = local_cas_pb2.FetchTreeRequest()
+            request.root_digest.CopyFrom(tree)
+            request.fetch_file_blobs = True
+
+            local_cas.FetchTree(request)
+
     # pull_tree():
     #
     # Pull a single Tree rather than a ref.

Reply via email to