Skip to content

GH-132566: Progressively delete files in pathlib.Path.move() #133852

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

barneygale
Copy link
Contributor

@barneygale barneygale commented May 10, 2025

Adjust pathlib.Path.move() so that each file and directory is deleted immediately after it is copied, rather than copying everything before deleting anything.

To achieve this, we rename _copy_from() to _iter_copy_from() and convert it to a generator that yields (source, target) path pairs. The Path.move() method deletes each source path after it's copied.

Adjust `pathlib.Path.move()` so that each file and directory is deleted
immediately after it is copied, rather than copying everything before
deleting anything.

To achieve this, we rename `_copy_from()` to `_iter_copy_from()` and
convert it to a generator that yields `(target, source)` pairs. The
`Path.move()` method deletes each source path after it's copied.
@graingert
Copy link
Contributor

Thanks for this! I'll try to take a look asap

@barneygale
Copy link
Contributor Author

barneygale commented May 10, 2025

👍 thanks. FWIW this patch makes _iter_copy_from() yield once after the copying a path. #131636 will make it yield whenever possible. I'll rebase that PR after this PR lands, if that makes sense

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants