Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
GH-125413: Add private metadata methods to pathlib.Path.info#129897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-125413: Add private metadata methods to pathlib.Path.info#129897
Uh oh!
There was an error while loading. Please reload this page.
Conversation
barneygale commented Feb 9, 2025 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Add the following private methods to `pathlib.Path.info`: - `_get_mode()`: returns the POSIX file mode (`st_mode`), or zero if `os.stat()` fails. - `_get_times_ns()`: returns the access and modify times in nanoseconds (`st_atime_ns` and `st_mtime_ns`), or zeroes if `os.stat()` fails. - `_get_flags()`: returns the BSD file flags (`st_flags`), or zero if `os.stat()` fails. - `_get_xattrs()`: returns the file extended attributes as a list of key, value pairs, or an empty list if `listxattr()` or `getattr()` fail. These methods replace `LocalCopyReader.read_metadata()`, and so we can delete the `CopyReader` and `LocalCopyReader` classes. Rather than reading metadata via `source._copy_reader.read_metadata()`, we instead call `source.info._get_mode()`, `_get_times_ns()`, etc. Copying metadata is only supported for local-to-local copies at the moment. To support copying between arbitrary `ReadablePath` and `WritablePath` objects, we'd need to make the new methods public and documented.
(not 100% sure about this)
encukou commented Feb 12, 2025
Should
Is that the plan? It seems to me that people will want their subclasses to support such copying, and are might resort to underscored functions to get it. |
barneygale commented Feb 12, 2025 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Sounds good to me. Would we (eventually) document it as returning
Yes, I think it will be part of the PEP for making Joinable/Readable/WritablePath public. |
encukou commented Feb 13, 2025
The tuple for the local FS†, a comparable/hashable object in general? I can imagine a path class that would add extra functionality to Path (or limit the functionality), but expose local files. |
barneygale commented Feb 13, 2025
Thanks :) I've deleted |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
barneygale commented Feb 17, 2025
Thanks for the review! |
7fcace9 into python:mainUh oh!
There was an error while loading. Please reload this page.
Replace `WritablePath._copy_writer` with a new `_write_info()` method. This method allows the target of a `copy()` to preserve metadata. Replace `pathlib._os.CopyWriter` and `LocalCopyWriter` classes with new `copy_file()` and `copy_info()` functions. The `copy_file()` function uses `source_path.info` wherever possible to save on `stat()`s.
Add the following private methods to
pathlib.Path.info:_posix_permissions(): the POSIX file permissions (S_IMODE(st_mode))_file_id(): the file ID ((st_dev, st_ino))_access_time_ns(): the access time in nanoseconds (st_atime_ns)_mod_time_ns(): the modify time in nanoseconds (st_mtime_ns)_bsd_flags(): the BSD file flags (st_flags)_xattrs(): the file extended attributes as a list of key, value pairs, or an empty list iflistxattr()orgetxattr()fail in an ignorable way.These methods replace
LocalCopyReader.read_metadata(), and so we can delete theCopyReaderandLocalCopyReaderclasses. Rather than reading metadata viasource._copy_reader.read_metadata(), we instead callsource.info._posix_permissions(),_access_time_ns(), etc.Preserving metadata is only supported for local-to-local copies at the moment. To support copying metadata between arbitrary
ReadablePathandWritablePathobjects, we'd need to make the new methods public and documented.os.DirEntryobjects from pathlib #125413