cpython icon indicating copy to clipboard operation
cpython copied to clipboard

GH-73991: Support preserving metadata in `pathlib.Path.copy()`

Open barneygale opened this issue 1 year ago • 0 comments

Add preserve_metadata keyword-only argument to pathlib.Path.copy(), defaulting to false. When set to true, we copy timestamps, permissions, extended attributes and flags where available, like shutil.copystat(). The argument has no effect on Windows, where metadata is always copied.

Internally (in the pathlib ABCs), path types gain _readable_metadata and _writable_metadata attributes. These sets of strings describe what kinds of metadata can be retrieved and stored. We take a union of source._readable_metadata and target._writable_metadata to minimise reads/writes. A new _read_metadata() method accepts a set of metadata keys and returns a dict with those keys, and a new _write_metadata() method accepts a dict of metadata. We might make these public in future, but it's hard to justify while the ABCs are still private.

  • Issue: gh-73991

📚 Documentation preview 📚: https://cpython-previews--120806.org.readthedocs.build/

barneygale avatar Jun 20 '24 18:06 barneygale