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

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

commit e169c1974113a21fb3dc5772dd41c16c52fe3a9a
Author: Jürg Billeter <[email protected]>
AuthorDate: Fri Oct 2 14:25:16 2026 +0200

    cascache.py: Replace existing files in `checkout` for symlinks
    
    `bst artifact checkout --force` intentionally replaces existing files.
    The same should apply to symlinks. Without `--force`, it should not be
    possible to hit that code path.
---
 src/buildstream/_cas/cascache.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/buildstream/_cas/cascache.py b/src/buildstream/_cas/cascache.py
index 5fecff654..b0187f296 100644
--- a/src/buildstream/_cas/cascache.py
+++ b/src/buildstream/_cas/cascache.py
@@ -225,7 +225,14 @@ class CASCache:
         for symlinknode in directory.symlinks:
             # symlink
             fullpath = os.path.join(dest, symlinknode.name)
-            os.symlink(symlinknode.target, fullpath)
+            try:
+                os.symlink(symlinknode.target, fullpath)
+            except FileExistsError:
+                try:
+                    os.unlink(fullpath)
+                except OSError as e:
+                    raise CASCacheError(f"Failed to remove destination file 
'{fullpath}': {e}") from e
+                os.symlink(symlinknode.target, fullpath)
 
         node_properties = directory.node_properties
         if node_properties.HasField("mtime"):

Reply via email to