Skip to content

Clear junction properly when uninstalling Python versions on Windows#18815

Open
woodruffw wants to merge 4 commits intomainfrom
ww/repro-18793
Open

Clear junction properly when uninstalling Python versions on Windows#18815
woodruffw wants to merge 4 commits intomainfrom
ww/repro-18793

Conversation

@woodruffw
Copy link
Copy Markdown
Member

@woodruffw woodruffw commented Apr 1, 2026

Summary

Reproduces and fixes #18793.

Previously, when uninstalling Python versions on Windows, we'd remove junctions (i.e. soft links) for the minor version after deleting the installation itself. This worked correctly on Linux and macOS but not on Windows, since on Windows we'd call junction::get_target (via PythonMinorVersionLink::exists), which would fail because the junction would be dangling following the deletion. Specifically, read_target returns None, short circuiting the target_directory check.

The fix here is to reorder the uninstallation flow so that we precompute and remove the links before the underlying installations are deleted. I've added two tests that both reproduced the behavior and now demonstrate the fix working.

Note: 81c27ba shows a smaller alternative fix -- instead of reordering the installation flow, we can change the "entry exists" logic on Windows to not require that the target still exists. I believe this would also be functionally correct, but I think reordering the uninstallation flow makes more sense (in terms of eliminating the surprising state rather than trying to work around it).

Test Plan

Look at me, I am the test plan now.

@woodruffw woodruffw self-assigned this Apr 1, 2026
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 2, 2026

Merging this PR will not alter performance

✅ 5 untouched benchmarks


Comparing ww/repro-18793 (d1980c2) with main (6571827)

Open in CodSpeed

Signed-off-by: William Woodruff <william@astral.sh>
Signed-off-by: William Woodruff <william@astral.sh>
Signed-off-by: William Woodruff <william@astral.sh>
Signed-off-by: William Woodruff <william@astral.sh>
@woodruffw woodruffw changed the title Attempt to repro #18793 Clear junction properly when uninstalling Python versions on Windows Apr 2, 2026
@woodruffw woodruffw marked this pull request as ready for review April 2, 2026 15:20
@woodruffw
Copy link
Copy Markdown
Member Author

Specifically, this is the problematic check in junction:

https://docs.rs/junction/1.4.2/src/junction/internals.rs.html#116-118

Path::exists() follows the junction and in this case the target has already been deleted, so junction::exists() fails-fast instead of proceeding to check the junction's actual metadata.

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

Labels

windows Specific to the Windows platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

the junction link is still exists after unistalling python by uv

1 participant