Skip to content

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

Open
barneygale wants to merge 4 commits into
python:mainfrom
barneygale:gh-132566
Open

GH-132566: Progressively delete files in pathlib.Path.move()#133852
barneygale wants to merge 4 commits into
python:mainfrom
barneygale:gh-132566

Conversation

@barneygale

@barneygale barneygale commented May 10, 2025

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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

@barneygale

barneygale commented May 10, 2025

Copy link
Copy Markdown
Contributor Author

👍 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
Copy Markdown
Contributor

sorry for the delay, this looks good to me!

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 24, 2026
@serhiy-storchaka serhiy-storchaka added the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label May 30, 2026
@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label May 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes topic-pathlib

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants