]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
GH-73991: Add `pathlib.Path.copy()` (#119058)
authorBarney Gale <barney.gale@gmail.com>
Fri, 14 Jun 2024 16:15:49 +0000 (17:15 +0100)
committerGitHub <noreply@github.com>
Fri, 14 Jun 2024 16:15:49 +0000 (17:15 +0100)
commit7c38097add9cc24e9f68414cd3e5e1b6cbe38a17
treec1855c18068a70e2d724cac84071d05c634fb091
parent2bacc2343c24c49292dea3461f6b7664fc2d33e2
GH-73991: Add `pathlib.Path.copy()` (#119058)

Add a `Path.copy()` method that copies the content of one file to another.

This method is similar to `shutil.copyfile()` but differs in the following ways:

- Uses `fcntl.FICLONE` where available (see GH-81338)
- Uses `os.copy_file_range` where available (see GH-81340)
- Uses `_winapi.CopyFile2` where available, even though this copies more metadata than the other implementations. This makes `WindowsPath.copy()` more similar to `shutil.copy2()`.

The method is presently _less_ specified than the `shutil` functions to allow OS-specific optimizations that might copy more or less metadata.

Incorporates code from GH-81338 and GH-93152.

Co-authored-by: Eryk Sun <eryksun@gmail.com>
Doc/library/pathlib.rst
Doc/whatsnew/3.14.rst
Lib/pathlib/_abc.py
Lib/pathlib/_local.py
Lib/pathlib/_os.py [new file with mode: 0644]
Lib/test/test_pathlib/test_pathlib_abc.py
Misc/NEWS.d/next/Library/2024-05-15-01-36-08.gh-issue-73991.CGknDf.rst [new file with mode: 0644]