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

Add `WritablePath.copy_from()`

Open barneygale opened this issue 7 months ago • 1 comments

To support metadata transfers, we need to add a method to WritablePath that allows receivers to copy metadata from some ReadablePath source. Currently we have _copy_from(), but it's got an underscore prefix.

This will affect pathlib.Path

Perhaps the method should return an iterator that emits progress reports? If so can someone come up with a better name than iter_copy_from()? :)

See also https://github.com/python/cpython/pull/131636

barneygale avatar Apr 28 '25 19:04 barneygale

Alternatively:

  • Add PathInfo.mode(), access_time() and modify_time() methods.
  • Add keyword-only info arguments to __open_writer__(), mkdir() and symlink_to(). If not None, methods are expected to copy metadata from the PathInfo object when creating files/directories/symlinks.
  • Implementations of these methods for (local filesystem) Path would apply the equivalent of the 'data' filter for tar files: https://docs.python.org/3/library/tarfile.html#tarfile.data_filter
    • __open_writer__() - access/modify times and limited permissions info
    • mkdir() - access/modify times only
    • symlink_to() - access/modify times only
  • Implementation of ReadablePath.copy() should call these methods rather than target._copy_from().
  • Implementation of Path.copy() should detect a local filesystem target and apply additional metadata with chmod() etc
    • xattrs
    • bsd flags
    • full permissions

barneygale avatar Sep 18 '25 18:09 barneygale