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 89c3b2f80c6658177700c6f76e05eef880467a2f
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 28f0dc57f..7342b9bbc 100644
--- a/src/buildstream/_cas/cascache.py
+++ b/src/buildstream/_cas/cascache.py
@@ -231,7 +231,14 @@ class CASCache:
             # symlink
             _validate_cas_node_name(symlinknode.name, names)
             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