diff options
author | Jürg Billeter <j@bitron.ch> | 2019-10-02 10:17:53 +0100 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2019-11-05 07:42:05 +0000 |
commit | 52cead24f8a8fe600a204b79046838be6c342675 (patch) | |
tree | ee8d7b710f3d56be830aa1873e9cb52116dc15d5 | |
parent | 336fef98998d847dcf3df7d520a6bc1b1f43cb14 (diff) | |
download | buildstream-52cead24f8a8fe600a204b79046838be6c342675.tar.gz |
cascache.py: Reimplement contains_directory() with FetchTree()
-rw-r--r-- | src/buildstream/_cas/cascache.py | 33 |
1 files changed, 12 insertions, 21 deletions
diff --git a/src/buildstream/_cas/cascache.py b/src/buildstream/_cas/cascache.py index b2158597e..022730445 100644 --- a/src/buildstream/_cas/cascache.py +++ b/src/buildstream/_cas/cascache.py @@ -255,30 +255,21 @@ class CASCache(): # Returns: True if the directory is available in the local cache # def contains_directory(self, digest, *, with_files): - try: - directory = remote_execution_pb2.Directory() - path = self.objpath(digest) - with open(path, 'rb') as f: - directory.ParseFromString(f.read()) - os.utime(f.fileno()) - - # Optionally check presence of files - if with_files: - for filenode in directory.files: - path = self.objpath(filenode.digest) - - # No need for separate `exists()` call as this will raise - # FileNotFoundError if the file does not exist. - os.utime(path) + local_cas = self._get_local_cas() - # Check subdirectories - for dirnode in directory.directories: - if not self.contains_directory(dirnode.digest, with_files=with_files): - return False + request = local_cas_pb2.FetchTreeRequest() + request.root_digest.CopyFrom(digest) + request.fetch_file_blobs = with_files + try: + local_cas.FetchTree(request) return True - except FileNotFoundError: - return False + 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(): # |