rustup
rustup copied to clipboard
`rustup self uninstall` failed, left system in mystery state
Problem
While trying to diagnose another problem (see issue I will file in a minute), I decided to try uninstalling and reinstalling Rustup.
When I sat down at my computer this morning it was running rustup 1.11.0 (e751ff9f8 2018-02-13). I then later did a rustup self update and got to 1.25.2 (17db695f1 2023-02-01). Some time after that, I tried rustup.exe self uninstall
C:\Users\Andi>rustup.exe self uninstall
Thanks for hacking in Rust!
This will uninstall all Rust toolchains and data, and remove
%USERPROFILE%\.cargo/bin from your PATH environment variable.
Continue? (y/N) y
info: removing rustup home
error: could not remove 'rustup_home' directory: 'C:\Users\Andi\.rustup': Access is denied. (os error 5)
This left my system in an unusual state. cargo.exe is no longer on the system, rustup.exe is still in %PATH%, .cargo and .rustup were still present but some items seem to be deleted out of .rustup:
C:\Users\Andi>dir .cargo
Volume in drive C has no label.
Volume Serial Number is 367D-9E05
Directory of C:\Users\Andi\.cargo
04/09/2023 02:51 PM <DIR> .
04/09/2023 02:51 PM <DIR> ..
04/22/2022 03:37 PM 0 .package-cache
04/24/2023 01:50 PM <DIR> bin
12/01/2022 07:07 PM 73 config.toml
04/09/2023 02:52 PM <DIR> git
11/26/2022 01:48 PM <DIR> registry
2 File(s) 73 bytes
5 Dir(s) 47,961,247,744 bytes free
C:\Users\Andi>dir .rustup
Volume in drive C has no label.
Volume Serial Number is 367D-9E05
Directory of C:\Users\Andi\.rustup
04/24/2023 02:11 PM <DIR> .
04/24/2023 02:11 PM <DIR> ..
04/24/2023 02:11 PM 48 settings.toml
04/23/2023 05:04 PM <DIR> tmp
1 File(s) 48 bytes
3 Dir(s) 47,961,247,744 bytes free
Re-running rustup self uninstall at this point results in the same error message as above.
Sometimes Windows gets weird ideas in its head about which files and directories are and aren't locked. I don't have .cargo or .rustup open in an Explorer or shell window. I have not tried reinstalling yet.
Steps
The bug does not appear to be reproducible. A very brave person on Mastodon running rustup 1.25.2 on Windows agreed to attempt rustup self uninstall and it ran fine for her.
Possible Solution(s)
Since this is a one-off problem, and could have been caused by something I did without realizing it, my primary concern is not that this happened. The "expected behavior" I would like to request is slightly better failure handling when this does happen:
- If possible, maybe it would be good for rustup to verify none of the directories or files it wishes to remove are locked by Windows before it starts making changes on disk.
- If this is not possible, at least the error message if an uninstall fails should give some sort of useful advice, such as "please try rebooting and then delete the directories %USERPROFILE%.cargo and %USERPROFILE%.rustup" (or whatever other manual steps the user would need to do to ensure their system is in an uninstalled state).
Notes
No response
Rustup version
At this second, rustup 1.25.2 (17db695f1 2023-02-01) I am running Windows 10 Version 10.0.19045 Build 19045. I ran all involved commands in CMD.COM but I did some cargo/rustup invocations with WSL earlier in the day.
Installed toolchains
Following all events above:
C:\Users\Andi>rustup show
Default host: x86_64-pc-windows-msvc
rustup home: C:\Users\Andi\.rustup
no active toolchain