summaryrefslogtreecommitdiff
path: root/src/buildstream/storage/_casbaseddirectory.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/buildstream/storage/_casbaseddirectory.py')
-rw-r--r--src/buildstream/storage/_casbaseddirectory.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/buildstream/storage/_casbaseddirectory.py b/src/buildstream/storage/_casbaseddirectory.py
index d6c4a7813..ed6fe206c 100644
--- a/src/buildstream/storage/_casbaseddirectory.py
+++ b/src/buildstream/storage/_casbaseddirectory.py
@@ -736,18 +736,23 @@ class CasBasedDirectory(Directory):
if mode not in ["r", "rb", "w", "wb", "x", "xb"]:
raise ValueError("Unsupported mode: `{}`".format(mode))
+ if "b" in mode:
+ encoding = None
+ else:
+ encoding = "utf-8"
+
if "r" in mode:
if not entry:
raise FileNotFoundError("{} not found in {}".format(path[-1], str(subdir)))
# Read-only access, allow direct access to CAS object
- with open(self.cas_cache.objpath(entry.digest), mode, encoding="utf-8") as f:
+ with open(self.cas_cache.objpath(entry.digest), mode, encoding=encoding) as f:
yield f
else:
if "x" in mode and entry:
raise FileExistsError("{} already exists in {}".format(path[-1], str(subdir)))
- with utils._tempnamedfile(mode, encoding="utf-8", dir=self.cas_cache.tmpdir) as f:
+ with utils._tempnamedfile(mode, encoding=encoding, dir=self.cas_cache.tmpdir) as f:
yield f
# Import written temporary file into CAS
f.flush()