summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2020-04-07 17:07:41 +0200
committerbst-marge-bot <marge-bot@buildstream.build>2020-04-08 06:57:57 +0000
commit90c164693ee2eb32e05325c14219c9329d14c386 (patch)
tree0567d0452b43b7d9713ada40d602bd16e2228d7b
parent937253e1ce249b6713b15fe95c61248b0f920e63 (diff)
downloadbuildstream-90c164693ee2eb32e05325c14219c9329d14c386.tar.gz
_filebaseddirectory.py: Fix encoding in open_file() for binary files
Python doesn't ignore `encoding` for binary files, it must be `None`.
-rw-r--r--src/buildstream/storage/_filebaseddirectory.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/buildstream/storage/_filebaseddirectory.py b/src/buildstream/storage/_filebaseddirectory.py
index 53a87b64c..1500dd78e 100644
--- a/src/buildstream/storage/_filebaseddirectory.py
+++ b/src/buildstream/storage/_filebaseddirectory.py
@@ -256,10 +256,15 @@ class FileBasedDirectory(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:
- return open(newpath, mode=mode, encoding="utf-8")
+ return open(newpath, mode=mode, encoding=encoding)
else:
- return utils.save_file_atomic(newpath, mode=mode, encoding="utf-8")
+ return utils.save_file_atomic(newpath, mode=mode, encoding=encoding)
def __str__(self):
# This returns the whole path (since we don't know where the directory started)