Skip to content

Commit 7fcace9

Browse files
barneygaleencukou
andauthored
GH-125413: Add private metadata methods to pathlib.Path.info (#129897)
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 if `listxattr()` or `getxattr()` fail in an ignorable way. 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._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` and `WritablePath` objects, we'd need to make the new methods public and documented. Co-authored-by: Petr Viktorin <[email protected]>
1 parent bd1642c commit 7fcace9

File tree

4 files changed

+204
-206
lines changed

4 files changed

+204
-206
lines changed

Lib/pathlib/_abc.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from abc import ABC, abstractmethod
1515
from glob import _PathGlobber, _no_recurse_symlinks
1616
from pathlib import PurePath, Path
17-
from pathlib._os import magic_open, CopyReader, CopyWriter
17+
from pathlib._os import magic_open, CopyWriter
1818

1919

2020
def _explode_path(path):
@@ -353,8 +353,6 @@ def readlink(self):
353353
"""
354354
raise NotImplementedError
355355

356-
_copy_reader = property(CopyReader)
357-
358356
def copy(self, target, follow_symlinks=True, dirs_exist_ok=False,
359357
preserve_metadata=False):
360358
"""

Lib/pathlib/_local.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
except ImportError:
2020
grp = None
2121

22-
from pathlib._os import LocalCopyReader, LocalCopyWriter, PathInfo, DirEntryInfo
22+
from pathlib._os import LocalCopyWriter, PathInfo, DirEntryInfo, ensure_different_files
2323

2424

2525
__all__ = [
@@ -1079,7 +1079,6 @@ def replace(self, target):
10791079
os.replace(self, target)
10801080
return self.with_segments(target)
10811081

1082-
_copy_reader = property(LocalCopyReader)
10831082
_copy_writer = property(LocalCopyWriter)
10841083

10851084
def copy(self, target, follow_symlinks=True, dirs_exist_ok=False,
@@ -1125,7 +1124,7 @@ def move(self, target):
11251124
else:
11261125
if not hasattr(target, '_copy_writer'):
11271126
target = self.with_segments(target_str)
1128-
target._copy_writer._ensure_different_file(self)
1127+
ensure_different_files(self, target)
11291128
try:
11301129
os.replace(self, target_str)
11311130
return target

0 commit comments

Comments
 (0)