diff options
author | Jürg Billeter <j@bitron.ch> | 2020-04-22 18:03:39 +0200 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2020-04-27 08:32:32 +0000 |
commit | 5e6dc5f1bbe43907804377f1c4598b9273afd3ab (patch) | |
tree | f2869fe187d04233b4c84b3fcf5a8481129ca52f | |
parent | a1c85b03824bf5b01868ad08c866c79501db5356 (diff) | |
download | buildstream-5e6dc5f1bbe43907804377f1c4598b9273afd3ab.tar.gz |
_filebaseddirectory.py: Fix mode="x" in open_file()
-rw-r--r-- | src/buildstream/storage/_filebaseddirectory.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/buildstream/storage/_filebaseddirectory.py b/src/buildstream/storage/_filebaseddirectory.py index c492c41cd..a2708c4eb 100644 --- a/src/buildstream/storage/_filebaseddirectory.py +++ b/src/buildstream/storage/_filebaseddirectory.py @@ -268,6 +268,13 @@ class FileBasedDirectory(Directory): if "r" in mode: return open(newpath, mode=mode, encoding=encoding) else: + if "x" in mode: + # This check is not atomic, however, we're operating with a + # single thread in a private directory tree. + if subdir.exists(path[-1]): + raise FileExistsError("{} already exists in {}".format(path[-1], str(subdir))) + mode = "w" + mode[1:] + return utils.save_file_atomic(newpath, mode=mode, encoding=encoding) def __str__(self): |