8000 GH-73991: Support preserving metadata in `pathlib.Path.copytree()` by barneygale · Pull Request #121438 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-73991: Support preserving metadata in pathlib.Path.copytree() #121438

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

Merged
merged 5 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Tweaks
  • Loading branch information
barneygale committed Jul 6, 2024
commit 2470fec6f3a69ef9f6b6cc8191a184b78c000e99
2 changes: 1 addition & 1 deletion Lib/pathlib/_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ def on_error(err):
sources = source_dir.iterdir()
target_dir.mkdir(exist_ok=dirs_exist_ok)
if preserve_metadata:
source_dir._copy_metadata(target_dir, follow_symlinks=True)
source_dir._copy_metadata(target_dir)
for source in sources:
if ignore and ignore(source):
continue
Expand Down
12 changes: 7 additions & 5 deletions Lib/test/test_pathlib/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,14 +722,16 @@ def test_copytree_preserve_metadata(self):
source.copytree(target, preserve_metadata=True)

for subpath in ['.', 'fileC', 'dirD', 'dirD/fileD']:
source_st = source.joinpath(subpath).stat()
target_st = target.joinpath(subpath).stat()
source_p = source / subpath
target_p = target / subpath
if hasattr(os, 'listxattr'):
if b'user.foo' in os.listxattr(source_p):
self.assertEqual(os.getxattr(target_p, b'user.foo'), b'42')
source_st = source_p.stat()
target_st = target_p.stat()
self.assertLessEqual(source_st.st_atime, target_st.st_atime)
self.assertLessEqual(source_st.st_mtime, target_st.st_mtime)
self.assertEqual(source_st.st_mode, target_st.st_mode)
if hasattr(os, 'listxattr'):
if b'user.foo' in os.listxattr(target):
self.assertEqual(os.getxattr(target, b'user.foo'), b'42')
if hasattr(source_st, 'st_flags'):
self.assertEqual(source_st.st_flags, target_st.st_flags)

Expand Down
Loading
0