From 6bc539055ccaa5b89ffb0841006141e5aafe0d0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Billeter?= Date: Wed, 2 Oct 2019 10:17:53 +0100 Subject: cascache.py: Reimplement contains_directory() with FetchTree() --- src/buildstream/_cas/cascache.py | 33 ++++++++++++--------------------- 1 file 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(): # -- cgit v1.2.1