8000 GH-130614: pathlib ABCs: improve support for receiving path metadata by barneygale · Pull Request #131259 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-130614: pathlib ABCs: improve support for receiving path metadata #131259

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 3 commits into from
Mar 16, 2025
Merged
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
Use a stack to implement _WritablePath._copy_from()
  • Loading branch information
barneygale committed Mar 14, 2025
commit 119822c9d408dc5d47fac784c146197612e6994d
27 changes: 15 additions & 12 deletions Lib/pathlib/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,18 +415,21 @@ def _copy_from(self, source, follow_symlinks=True):
"""
Recursively copy the given path to this path.
"""
if not follow_symlinks and source.info.is_symlink():
self.symlink_to(str(source.readlink()), source.info.is_dir())
elif source.info.is_dir():
children = source.iterdir()
self.mkdir()
for child in children:
self.joinpath(child.name)._copy_from(child, follow_symlinks)
else:
ensure_different_files(source, self)
with magic_open(source, 'rb') as source_f:
with magic_open(self, 'wb') as target_f:
copyfileobj(source_f, target_f)
stack = [(source, self)]
while stack:
src, dst = stack.pop()
if not follow_symlinks and src.info.is_symlink():
dst.symlink_to(str(src.readlink()), src.info.is_dir())
elif src.info.is_dir():
children = src.iterdir()
dst.mkdir()
for child in children:
stack.append((child, dst.joinpath(child.name)))
else:
ensure_different_files(src, dst)
with magic_open(src, 'rb') as source_f:
with magic_open(dst, 'wb') as target_f:
copyfileobj(source_f, target_f)


_JoinablePath.register(PurePath)
Expand Down
Loading
0