summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2020-10-28 09:14:45 +0100
committerJürg Billeter <j@bitron.ch>2020-12-09 14:51:06 +0000
commita501b0e60f15779be0abb7b074dd6e4944b1a23a (patch)
treecd3e41a1792e00feb240f25483717822c25fd282 /src
parent8c697671cc9a717020839d2e38fd9e1a42449855 (diff)
downloadbuildstream-a501b0e60f15779be0abb7b074dd6e4944b1a23a.tar.gz
cascache.py: Add open() method
Diffstat (limited to 'src')
-rw-r--r--src/buildstream/_cas/cascache.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/buildstream/_cas/cascache.py b/src/buildstream/_cas/cascache.py
index 2fa143084..b875eecdd 100644
--- a/src/buildstream/_cas/cascache.py
+++ b/src/buildstream/_cas/cascache.py
@@ -272,6 +272,22 @@ class CASCache:
def objpath(self, digest):
return os.path.join(self.casdir, "objects", digest.hash[:2], digest.hash[2:])
+ # open():
+ #
+ # Open file read-only by CAS digest and return a corresponding file object.
+ #
+ # Args:
+ # digest (Digest): The digest of the object
+ # mode (str): An optional string that specifies the mode in which the file is opened.
+ #
+ def open(self, digest, mode="r"):
+ if mode not in ["r", "rb"]:
+ raise ValueError("Unsupported mode: `{}`".format(mode))
+
+ objpath = self.objpath(digest)
+
+ return open(objpath, mode=mode)
+
# add_object():
#
# Hash and write object to CAS.