Skip to content

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

@graingert
Copy link
Contributor

sorry for the delay, this looks good to me!

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