You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Path.copy() silently truncates the source when a reused destination path becomes a hard link to it #162689
On Linux, Path.copy() can return successfully after emptying its source file. This happens when an earlier copy used the same destination Path object and the destination was subsequently replaced with a hard link to the source.
Expected: The second copy() raises OSError and preserves b"original data". Replacing only that call with src.copy(Path(dst)) produces this behavior on the same files.
Actual: The second copy() returns normally and the output is b'' b''.
The first copy caches the destination’s file identity. After dst is replaced, src.samefile(dst) correctly returns True, but the same-file check inside copy() uses the old identity. It then opens dst in wb mode, truncating the shared inode before any bytes are copied. The reproducer is single-threaded and never accesses Path.info explicitly.
Reproduced on Linux with CPython 3.14.10, 3.15.2, 3.16.0a2, and main at 3b309372.
Activity