Bug report
Bug description:
Bug report
Path.copy() guards against copying a directory into itself with ensure_distinct_paths(), but the check is lexical only. Relative vs absolute paths and symlink aliases bypass it.
from pathlib import Path
import os
Path('src').mkdir()
(Path('src') / 'f').write_text('hello')
Path('src').copy('src/nested') # OSError - OK
Path('src').copy(Path('src').resolve() / 'nested') # succeeds - copies into itself
os.symlink('src', 'link')
Path('src').copy('link/nested') # also succeeds
Same class of bug as gh-149835 that was fixed with `realpath`, but `pathlib` still uses a lexical comparison.
### CPython versions tested on:
CPython main branch
### Operating systems tested on:
Linux
<!-- gh-linked-prs -->
### Linked PRs
* gh-154689
<!-- /gh-linked-prs -->
Bug report
Bug description:
Bug report
Path.copy()guards against copying a directory into itself withensure_distinct_paths(), but the check is lexical only. Relative vs absolute paths and symlink aliases bypass it.