This is an automated email from the ASF dual-hosted git repository.

juergbi pushed a commit to branch jbilleter/filebaseddirectory
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 5123af1e0ff3de9454c036e88bf9d5889babe66c
Author: Jürg Billeter <[email protected]>
AuthorDate: Sat Oct 3 20:40:17 2026 +0200

    _filebaseddirectory.py: Improve checks in `open_file()`
    
    Match the behavior of `CasBasedDirectory`.
---
 src/buildstream/storage/_filebaseddirectory.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/buildstream/storage/_filebaseddirectory.py 
b/src/buildstream/storage/_filebaseddirectory.py
index 0750b9168..f5fd8e7ce 100644
--- a/src/buildstream/storage/_filebaseddirectory.py
+++ b/src/buildstream/storage/_filebaseddirectory.py
@@ -142,6 +142,9 @@ class FileBasedDirectory(Directory):
         subdir = self.__open_directory(paths[:-1])
         newpath = os.path.join(subdir.__external_directory, paths[-1])
 
+        if subdir.exists(paths[-1]) and not subdir.isfile(paths[-1]):
+            raise DirectoryError("{} in {} is not a file".format(paths[-1], 
str(subdir)))
+
         if mode not in ["r", "rb", "w", "wb", "w+", "w+b", "x", "xb", "x+", 
"x+b"]:
             raise ValueError("Unsupported mode: `{}`".format(mode))
 
@@ -157,8 +160,8 @@ class FileBasedDirectory(Directory):
             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 DirectoryError("{} already exists in 
{}".format(path[-1], str(subdir)))
+                if subdir.exists(paths[-1]):
+                    raise DirectoryError("{} already exists in 
{}".format(paths[-1], str(subdir)))
                 mode = "w" + mode[1:]
 
             with utils.save_file_atomic(newpath, mode=mode, encoding=encoding) 
as f:

Reply via email to