Repository navigation
Replace existing destinations when merging symbolic links - #282
Aschenbath wants to merge 1 commit into
Conversation
MateehUllah
left a comment
There was a problem hiding this comment.
On macOS with CPython 3.13.13, the merge-tree tests passed (11 passed), as did the package and test-directory run (147 passed, one skipped). I also checked copying a relative dangling link and replacing a self-referential link in a temporary directory. Both worked. I found one case where a failed link creation removes the old destination, detailed inline. Verified with Codex assistance.
| dest = dst_path / source.name | ||
| if symlinks and source.islink(): | ||
| target = source.readlink() | ||
| if not dest.islink() and dest.is_dir(): |
There was a problem hiding this comment.
Could we create the replacement link in the destination directory before removing the old entry? I reproduced this on macOS with an ACL that denies add_file while allowing deletion. When the source link collides with an existing file, this branch removes the file and then target.symlink(dest) raises PermissionError. The base revision raises FileExistsError and leaves the existing file intact. An injected symlink-creation failure also confirmed the same loss for existing directories and links. Staging the new link under a temporary sibling name would preserve the old entry when link creation is denied.
merge_tree(symlinks=True)now replaces an existing destination before copying a symbolic link. Repeated merges work when the old destination is a link (including a dangling link), a file, or a directory. Replacing a destination link leaves its target untouched, and relative link targets remain relative.Fixes #263.
Validation: all five new regression cases fail on the original code; the merge-tree tests pass after the fix. The repository's tox environment on Windows / Python 3.12 passes all checks: 163 passed, 7 platform skips, including Ruff, mypy, package metadata, and coverage (98%).
Developed with Codex assistance.