pathlib-abc icon indicating copy to clipboard operation
pathlib-abc copied to clipboard

File transfer support

Open barneygale opened this issue 1 year ago • 1 comments

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() and chmod(), but suppress UnsupportedOperation
  • Copy symlinks with is_symlink(), readlink() and symlink_to() if the user sets follow_symlinks=False (and if they fail with UnsupportedOperation, copy the symlink contents?)

PathBase.copytree() should:

  • Call walk() to iterate over the source
  • Call mkdir() to create directories, but suppress UnsupportedOperation
  • Call copy() to copy files

Implementations in Path should use shutil when a os.PathLike argument is given, and call super() otherwise.

barneygale avatar Jan 19 '24 00:01 barneygale

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.

barneygale avatar Aug 26 '24 18:08 barneygale

Resolving this issue, as we have ReadablePath.copy() in 0.4.0.

barneygale avatar Mar 22 '25 20:03 barneygale