merge_tree(symlinks=True) cannot overwrite an existing destination symlink

Open Beginner friendly
#263 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

  • #264 by @00200200 — closed without merging

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python

Research direction

Start at the Python implementation of Path.merge_tree and reproduce the supplied example with symlinks=True. Trace the symlink destination handling, then verify that a second merge succeeds and that changed targets, files, and directories at the destination are replaced as described.

Written by the indexing model from the issue text.

Description

When merge_tree is used to re-sync a directory tree that contains symbolic links (for example a deploy or backup copy run more than once), the second call fails:

FileExistsError: [Errno 17] File exists: .../file.txt -> .../link.txt

Regular files are overwritten via copy2, and the docstring says merge_tree copies "overwriting existing contents in dst". Symlinks take a different path that calls os.symlink without replacing dest, so a repeated merge cannot complete.

from path import Path

src, dst = Path('A'), Path('B')
src.mkdir(); dst.mkdir()
(src / 'file.txt').write_text('hello')
(src / 'file.txt').symlink(src / 'link.txt')
src.merge_tree(dst, True)
src.merge_tree(dst, True)  # FileExistsError

Expected: the second merge succeeds and the destination symlink is replaced (including when the link target has changed, or when dest is a file/directory with the same name).

Dominant language
Python
Stars
1.1k
Forks
172
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from jaraco/path

All issues in jaraco/path

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.