Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
GH-125413: Add private metadata methods topathlib.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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
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 candelete the `CopyReader` and `LocalCopyReader` classes. Rather than readingmetadata 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)
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 commentedFeb 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. |
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 (orlimit the functionality), but expose local files. |
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.
Thanks for the review! |
7fcace9
intopython:mainUh oh!
There was an error while loading.Please reload this page.
Replace `WritablePath._copy_writer` with a new `_write_info()` method. Thismethod 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.
Uh oh!
There was an error while loading.Please reload this page.
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 theCopyReader
andLocalCopyReader
classes. 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
ReadablePath
andWritablePath
objects, we'd need to make the new methods public and documented.os.DirEntry
objects from pathlib #125413