summaryrefslogtreecommitdiff
path: root/src/buildstream/_cas
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2020-10-29 17:15:27 +0100
committerJürg Billeter <j@bitron.ch>2020-12-09 14:51:06 +0000
commit8c697671cc9a717020839d2e38fd9e1a42449855 (patch)
tree67f80e41d5e0c1123cbcfd3d91270f832b9e8d9b /src/buildstream/_cas
parent698330a601bcd51d7517edd9fc5466a136f1b1db (diff)
downloadbuildstream-8c697671cc9a717020839d2e38fd9e1a42449855.tar.gz
cascache.py: Generalize remote_missing_blobs() into missing_blobs()
The implementation can be reused to replace `local_missing_blobs()` and simplify `contains_files()`.
Diffstat (limited to 'src/buildstream/_cas')
-rw-r--r--src/buildstream/_cas/cascache.py43
1 files changed, 12 insertions, 31 deletions
diff --git a/src/buildstream/_cas/cascache.py b/src/buildstream/_cas/cascache.py
index aa9bf17df..2fa143084 100644
--- a/src/buildstream/_cas/cascache.py
+++ b/src/buildstream/_cas/cascache.py
@@ -152,13 +152,7 @@ class CASCache:
# Returns: True if the files are in the cache, False otherwise
#
def contains_files(self, digests):
- cas = self.get_cas()
-
- request = remote_execution_pb2.FindMissingBlobsRequest()
- request.blob_digests.extend(digests)
-
- response = cas.FindMissingBlobs(request)
- return len(response.missing_blob_digests) == 0
+ return len(self.missing_blobs(digests)) == 0
# contains_directory():
#
@@ -400,7 +394,7 @@ class CASCache:
return utils._message_digest(root_directory)
- # remote_missing_blobs_for_directory():
+ # missing_blobs_for_directory():
#
# Determine which blobs of a directory tree are missing on the remote.
#
@@ -409,23 +403,27 @@ class CASCache:
#
# Returns: List of missing Digest objects
#
- def remote_missing_blobs_for_directory(self, remote, digest):
+ def missing_blobs_for_directory(self, digest, *, remote=None):
required_blobs = self.required_blobs_for_directory(digest)
- return self.remote_missing_blobs(remote, required_blobs)
+ return self.missing_blobs(required_blobs, remote=remote)
- # remote_missing_blobs():
+ # missing_blobs():
#
- # Determine which blobs are missing on the remote.
+ # Determine which blobs are missing locally or on the remote.
#
# Args:
# blobs ([Digest]): List of directory digests to check
#
# Returns: List of missing Digest objects
#
- def remote_missing_blobs(self, remote, blobs):
+ def missing_blobs(self, blobs, *, remote=None):
cas = self.get_cas()
- instance_name = remote.local_cas_instance_name
+
+ if remote:
+ instance_name = remote.local_cas_instance_name
+ else:
+ instance_name = ""
missing_blobs = dict()
# Limit size of FindMissingBlobs request
@@ -450,23 +448,6 @@ class CASCache:
return missing_blobs.values()
- # local_missing_blobs():
- #
- # Check local cache for missing blobs.
- #
- # Args:
- # digests (list): The Digests of blobs to check
- #
- # Returns: Missing Digest objects
- #
- def local_missing_blobs(self, digests):
- missing_blobs = []
- for digest in digests:
- objpath = self.objpath(digest)
- if not os.path.exists(objpath):
- missing_blobs.append(digest)
- return missing_blobs
-
# required_blobs_for_directory():
#
# Generator that returns the Digests of all blobs in the tree specified by