diff options
author | Jürg Billeter <j@bitron.ch> | 2020-04-07 17:07:41 +0200 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2020-04-08 06:57:57 +0000 |
commit | 90c164693ee2eb32e05325c14219c9329d14c386 (patch) | |
tree | 0567d0452b43b7d9713ada40d602bd16e2228d7b /src/buildstream/storage | |
parent | 937253e1ce249b6713b15fe95c61248b0f920e63 (diff) | |
download | buildstream-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`.
Diffstat (limited to 'src/buildstream/storage')
-rw-r--r-- | src/buildstream/storage/_filebaseddirectory.py | 9 |
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) |