pathlib-abc
pathlib-abc copied to clipboard
File transfer support
Add methods like PathBase.copy() and copytree() that support copying files and directories from one path object to another.
PathBase.copy() should:
- Call
open()methods on the source and destination to transfer data - Attempt to copy permissions with
stat()andchmod(), but suppressUnsupportedOperation - Copy symlinks with
is_symlink(),readlink()andsymlink_to()if the user setsfollow_symlinks=False(and if they fail withUnsupportedOperation, copy the symlink contents?)
PathBase.copytree() should:
- Call
walk()to iterate over the source - Call
mkdir()to create directories, but suppressUnsupportedOperation - Call
copy()to copy files
Implementations in Path should use shutil when a os.PathLike argument is given, and call super() otherwise.
Upstream issue is fixed: https://github.com/python/cpython/issues/73991
Support for copying metadata is primitive and not particularly easy to customise, as it's hidden behind some underscore-prefixed methods. It will need some work, and probably a new Copier or Creator class.
Resolving this issue, as we have ReadablePath.copy() in 0.4.0.