Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
barneygale merged 16 commits intopython:mainfrombarneygale:gh-125413-merge-copyreader
Feb 17, 2025

Conversation

barneygale
Copy link
Contributor

@barneygalebarneygale commentedFeb 9, 2025
edited
Loading

Add the following private methods topathlib.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 replaceLocalCopyReader.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 arbitraryReadablePath andWritablePath objects, we'd need to make the new methods public and documented.

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.
@encukou
Copy link
Member

Should_file_id return a(st_dev, st_ino) tuple? AFAIK, separating them is only due to a low-level detail (you don't need to storest_dev on the disk).


To support copying metadata between arbitrary ReadablePath and WritablePath objects, we'd need to make the new methods public and documented.

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
Copy link
ContributorAuthor

barneygale commentedFeb 12, 2025
edited
Loading

Should_file_id return a(st_dev, st_ino) tuple? AFAIK, separating them is only due to a low-level detail (you don't need to storest_dev on the disk).

Sounds good to me. Would we (eventually) document it as returning(st_dev, st_ino), or should we just say "some comparable/hashable object"?

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.

Yes, I think it will be part of the PEP for making Joinable/Readable/WritablePath public.

@encukou
Copy link
Member

Sounds good to me. Would we (eventually) document it as returning(st_dev, st_ino), or should we just say "some comparable/hashable object"?

The tuple for the local FS†, a comparable/hashable object in general?
† (Not sure if there's something better for Windows?)

I can imagine a path class that would add extra functionality to Path (orlimit the functionality), but expose local files.

barneygale reacted with thumbs up emoji

@barneygale
Copy link
ContributorAuthor

Thanks :) I've deleted_device_id(), and made_file_id() return(st_dev, st_ino)

@barneygalebarneygaleenabled auto-merge (squash)February 17, 2025 18:54
@barneygale
Copy link
ContributorAuthor

Thanks for the review!

encukou reacted with heart emoji

@barneygalebarneygale merged commit7fcace9 intopython:mainFeb 17, 2025
38 checks passed
barneygale added a commit to barneygale/cpython that referenced this pull requestFeb 17, 2025
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.
barneygale added a commit to barneygale/cpython that referenced this pull requestFeb 21, 2025
barneygale added a commit to barneygale/cpython that referenced this pull requestFeb 24, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@encukouencukouencukou approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@barneygale@encukou

[8]ページ先頭

©2009-2025 Movatter.jp