From c836b7be6feaa0b9f86ab8c0cb5b913b0d8ed0e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Billeter?= Date: Wed, 28 Oct 2020 09:19:05 +0100 Subject: Use CASCache.open() --- src/buildstream/_artifact.py | 5 +++-- src/buildstream/_artifactcache.py | 2 +- src/buildstream/_cas/cascache.py | 3 +-- src/buildstream/_elementsourcescache.py | 2 +- src/buildstream/sandbox/_sandboxremote.py | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/buildstream/_artifact.py b/src/buildstream/_artifact.py index b92600a5a..d4a716ff1 100644 --- a/src/buildstream/_artifact.py +++ b/src/buildstream/_artifact.py @@ -370,8 +370,9 @@ class Artifact: # Load the public data from the artifact artifact = self._get_proto() - meta_file = self._cas.objpath(artifact.public_data) - data = _yaml.load(meta_file, shortname="public.yaml") + with self._cas.open(artifact.public_data) as meta_file: + meta_str = meta_file.read() + data = _yaml.load_data(meta_str, file_name="public.yaml") return data diff --git a/src/buildstream/_artifactcache.py b/src/buildstream/_artifactcache.py index 41a620b49..ded87679a 100644 --- a/src/buildstream/_artifactcache.py +++ b/src/buildstream/_artifactcache.py @@ -510,7 +510,7 @@ class ArtifactCache(AssetCache): # Fetch and parse artifact proto self.cas.fetch_blobs(remote, [artifact_digest]) artifact = artifact_pb2.Artifact() - with open(self.cas.objpath(artifact_digest), "rb") as f: + with self.cas.open(artifact_digest, "rb") as f: artifact.ParseFromString(f.read()) # Write the artifact proto to cache diff --git a/src/buildstream/_cas/cascache.py b/src/buildstream/_cas/cascache.py index b875eecdd..b80460abf 100644 --- a/src/buildstream/_cas/cascache.py +++ b/src/buildstream/_cas/cascache.py @@ -543,8 +543,7 @@ class CASCache: tree = remote_execution_pb2.Tree() - objpath = self.objpath(digest) - with open(objpath, "rb") as f: + with self.open(digest, "rb") as f: tree.ParseFromString(f.read()) dirbuffers = [tree.root.SerializeToString()] diff --git a/src/buildstream/_elementsourcescache.py b/src/buildstream/_elementsourcescache.py index 9a617b8d6..194f3fd4a 100644 --- a/src/buildstream/_elementsourcescache.py +++ b/src/buildstream/_elementsourcescache.py @@ -299,7 +299,7 @@ class ElementSourcesCache(AssetCache): # Fetch and parse source proto self.cas.fetch_blobs(remote, [source_digest]) source = source_pb2.Source() - with open(self.cas.objpath(source_digest), "rb") as f: + with self.cas.open(source_digest, "rb") as f: source.ParseFromString(f.read()) # Write the source proto to cache diff --git a/src/buildstream/sandbox/_sandboxremote.py b/src/buildstream/sandbox/_sandboxremote.py index 3302b0dad..ff314adba 100644 --- a/src/buildstream/sandbox/_sandboxremote.py +++ b/src/buildstream/sandbox/_sandboxremote.py @@ -380,13 +380,13 @@ class SandboxRemote(SandboxREAPI): # Forward remote stdout and stderr if stdout: if action_result.stdout_digest.hash: - with open(cascache.objpath(action_result.stdout_digest), "r") as f: + with cascache.open(action_result.stdout_digest, "r") as f: shutil.copyfileobj(f, stdout) elif action_result.stdout_raw: stdout.write(str(action_result.stdout_raw, "utf-8", errors="ignore")) if stderr: if action_result.stderr_digest.hash: - with open(cascache.objpath(action_result.stderr_digest), "r") as f: + with cascache.open(action_result.stderr_digest, "r") as f: shutil.copyfileobj(f, stderr) elif action_result.stderr_raw: stderr.write(str(action_result.stderr_raw, "utf-8", errors="ignore")) -- cgit v1.2.1