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
Merged
Changes from1 commit
Commits
Show all changes
16 commits
Select commitHold shift + click to select a range
4dd7c21
GH-125413: Add private metadata methods to `pathlib.Path.info`
barneygaleFeb 9, 2025
30faab7
Fix atime/mtime copying
barneygaleFeb 9, 2025
22e065d
Simplify patch
barneygaleFeb 9, 2025
cd4a1b5
Improve naming
barneygaleFeb 9, 2025
07f89a4
Return `None` if results aren't available.
barneygaleFeb 9, 2025
2026886
Merge `_create_metadata()` and `_create_symlink_metadata()`
barneygaleFeb 9, 2025
ba4d393
Simplify patch a bit
barneygaleFeb 9, 2025
6cde4fb
Further reduce diff
barneygaleFeb 9, 2025
0871a39
Stop suppressing stat() errors from new methods
barneygaleFeb 9, 2025
89e49bf
Stop using `samefile()`, add `_file_id()` and `_device_id()`
barneygaleFeb 11, 2025
86b671f
Attempt to fix access time test
barneygaleFeb 12, 2025
f6b2249
Delete `_device_id()`
barneygaleFeb 13, 2025
47616de
Merge branch 'main' into gh-125413-merge-copyreader
barneygaleFeb 13, 2025
bc9032b
Merge branch 'main' into gh-125413-merge-copyreader
barneygaleFeb 16, 2025
6c03d51
Merge branch 'main' into gh-125413-merge-copyreader
encukouFeb 17, 2025
13db1fe
`_create_metadata` -> `_copy_metadata`
barneygaleFeb 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Improve naming
  • Loading branch information
@barneygale
barneygale committedFeb 9, 2025
commitcd4a1b51702b2cb26d08e3772caa8725c3f6471a
101 changes: 53 additions & 48 deletionsLib/pathlib/_os.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -323,33 +323,35 @@ def _create_metadata(self, source):
"""Copy metadata from the given path to our path."""
target = self._path
info = source.info
copy_times_ns = hasattr(info, '_get_atime_ns') and hasattr(info, '_get_mtime_ns')
copy_xattrs = hasattr(info, '_get_xattrs') and hasattr(os, 'setxattr')
copy_mode = hasattr(info, '_get_mode')
copy_flags = hasattr(info, '_get_flags') and hasattr(os, 'chflags')

copy_times_ns = hasattr(info, '_access_time_ns') and hasattr(info, '_mod_time_ns')
if copy_times_ns:
atime_ns = info._get_atime_ns()
mtime_ns = info._get_mtime_ns()
if atime_ns and mtime_ns:
os.utime(target, ns=(atime_ns, mtime_ns))
access_time_ns = info._access_time_ns()
mod_time_ns = info._mod_time_ns()
if access_time_ns and mod_time_ns:
os.utime(target, ns=(access_time_ns, mod_time_ns))

copy_xattrs = hasattr(info, '_xattrs') and hasattr(os, 'setxattr')
if copy_xattrs:
xattrs = info._get_xattrs()
xattrs = info._xattrs()
for attr, value in xattrs:
try:
os.setxattr(target, attr, value)
except OSError as e:
if e.errno not in (EPERM, ENOTSUP, ENODATA, EINVAL, EACCES):
raise
if copy_mode:
mode = info._get_mode()
if mode:
os.chmod(target, S_IMODE(mode))
if copy_flags:
flags = info._get_flags()
if flags:

copy_posix_permissions = hasattr(info, '_posix_permissions')
if copy_posix_permissions:
posix_permissions = info._posix_permissions()
if posix_permissions:
os.chmod(target, posix_permissions)

copy_bsd_flags = hasattr(info, '_bsd_flags') and hasattr(os, 'chflags')
if copy_bsd_flags:
bsd_flags = info._bsd_flags()
if bsd_flags:
try:
os.chflags(target,flags)
os.chflags(target,bsd_flags)
except OSError as why:
if why.errno not in (EOPNOTSUPP, ENOTSUP):
raise
Expand All@@ -358,43 +360,46 @@ def _create_symlink_metadata(self, source):
"""Copy metadata from the given symlink to our symlink."""
target = self._path
info = source.info
copy_times_ns = (hasattr(info, '_get_atime_ns') and
hasattr(info, '_get_mtime_ns') and

copy_times_ns = (hasattr(info, '_access_time_ns') and
hasattr(info, '_mod_time_ns') and
os.utime in os.supports_follow_symlinks)
copy_xattrs = (hasattr(info, '_get_xattrs') and
if copy_times_ns:
access_time_ns = info._access_time_ns(follow_symlinks=False)
mod_time_ns = info._mod_time_ns(follow_symlinks=False)
if access_time_ns and mod_time_ns:
os.utime(target, ns=(access_time_ns, mod_time_ns), follow_symlinks=False)

copy_xattrs = (hasattr(info, '_xattrs') and
hasattr(os, 'setxattr') and
os.setxattr in os.supports_fd)
copy_mode = (hasattr(info, '_get_mode') and
hasattr(os, 'lchmod'))
copy_flags = (hasattr(info, '_get_flags') and
hasattr(os, 'chflags') and
os.chflags in os.supports_follow_symlinks)

if copy_times_ns:
atime_ns = info._get_atime_ns(follow_symlinks=False)
mtime_ns = info._get_mtime_ns(follow_symlinks=False)
if atime_ns and mtime_ns:
os.utime(target, ns=(atime_ns, mtime_ns), follow_symlinks=False)
if copy_xattrs:
xattrs = info._get_xattrs(follow_symlinks=False)
xattrs = info._xattrs(follow_symlinks=False)
for attr, value in xattrs:
try:
os.setxattr(target, attr, value, follow_symlinks=False)
except OSError as e:
if e.errno not in (EPERM, ENOTSUP, ENODATA, EINVAL, EACCES):
raise
if copy_mode:
mode = info._get_mode(follow_symlinks=False)
if mode:

copy_posix_permissions = (hasattr(info, '_posix_permissions') and
hasattr(os, 'lchmod'))
if copy_posix_permissions:
posix_permissions = info._posix_permissions(follow_symlinks=False)
if posix_permissions:
try:
os.lchmod(target,S_IMODE(mode))
os.lchmod(target,posix_permissions)
except NotImplementedError:
pass
if copy_flags:
flags = info._get_flags(follow_symlinks=False)
if flags:

copy_bsd_flags = (hasattr(info, '_bsd_flags') and
hasattr(os, 'chflags') and
os.chflags in os.supports_follow_symlinks)
if copy_bsd_flags:
bsd_flags = info._bsd_flags(follow_symlinks=False)
if bsd_flags:
try:
os.chflags(target,flags, follow_symlinks=False)
os.chflags(target,bsd_flags, follow_symlinks=False)
except OSError as why:
if why.errno not in (EOPNOTSUPP, ENOTSUP):
raise
Expand DownExpand Up@@ -476,37 +481,37 @@ def is_symlink(self):
return False
return S_ISLNK(st.st_mode)

def_get_mode(self, *, follow_symlinks=True):
"""Return the POSIX filemode, or zero if stat() fails."""
def_posix_permissions(self, *, follow_symlinks=True):
"""Return the POSIX filepermissions, or zero if stat() fails."""
st = self._stat(follow_symlinks=follow_symlinks)
if st is None:
return 0
return st.st_mode
returnS_IMODE(st.st_mode)

def_get_atime_ns(self, *, follow_symlinks=True):
def_access_time_ns(self, *, follow_symlinks=True):
"""Return the access time in nanoseconds, or zero if stat() fails."""
st = self._stat(follow_symlinks=follow_symlinks)
if st is None:
return 0
return st.st_atime_ns

def_get_mtime_ns(self, *, follow_symlinks=True):
def_mod_time_ns(self, *, follow_symlinks=True):
"""Return the modify time in nanoseconds, or zero if stat() fails."""
st = self._stat(follow_symlinks=follow_symlinks)
if st is None:
return 0
return st.st_mtime_ns

if hasattr(os.stat_result, 'st_flags'):
def_get_flags(self, *, follow_symlinks=True):
def_bsd_flags(self, *, follow_symlinks=True):
"""Return the flags, or zero if stat() fails."""
st = self._stat(follow_symlinks=follow_symlinks)
if st is None:
return 0
return st.st_flags

if hasattr(os, 'listxattr'):
def_get_xattrs(self, *, follow_symlinks=True):
def_xattrs(self, *, follow_symlinks=True):
"""Return the xattrs as a list of (attr, value) pairs, or an empty
list if extended attributes aren't supported."""
try:
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp