Skip to content

fix: stop remove $CARGO_HOME on uninstallation#4861

Open
Cloud0310 wants to merge 3 commits into
rust-lang:mainfrom
Cloud0310:main
Open

fix: stop remove $CARGO_HOME on uninstallation#4861
Cloud0310 wants to merge 3 commits into
rust-lang:mainfrom
Cloud0310:main

Conversation

@Cloud0310
Copy link
Copy Markdown
Contributor

fix #285
This PR fix the cargo bin nuke and the path removing possilble toutoc issue.
Here's the implementation details:

  • compare cargo bin dir content to rustup binary, if it's a link, remove it
  • then, we remove the rustup binary, on success, we then remove the cargo bin from path

This prevents rustup self uninstall from nuking out the $CARGO_HOME/bin and possible toctou problem of removing up the path.

Comment thread tests/suite/cli_self_upd.rs
@Cloud0310 Cloud0310 marked this pull request as ready for review May 19, 2026 10:37
@Cloud0310
Copy link
Copy Markdown
Contributor Author

Cloud0310 commented May 19, 2026

I think I may need more tests against this PR, this includes:

  • $CARGO_HOME/bin with unrelated files
  • empty bin cleanup test

Should there be more tests? Please let me know @FranciscoTGouveia @rami3l .

Comment thread src/cli/self_update/unix.rs Outdated
pub(crate) fn delete_rustup_and_cargo_home(process: &Process) -> Result<()> {
let cargo_home = process.cargo_home()?;
utils::remove_dir("cargo_home", &cargo_home)
pub(crate) fn remove_rustup_executable(process: &Process, no_modify_path: bool) -> Result<()> {
Copy link
Copy Markdown
Member

@rami3l rami3l May 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe delete_rustup_and_bin_dir() would be a better name for this, wdyt?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reasonable to me, I guess we may even need to add extra comments for this function?
It's actually does:

  • remove executable
  • cleanup $CARGO_HOME/bin on empty
  • cleanup $PATH

So, I propose the new name as delete_exe_and_cargo_bin?
And we should add comments for this function for clarification.

Copy link
Copy Markdown
Contributor

@FranciscoTGouveia FranciscoTGouveia May 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be overlooking something, but $CARGO_HOME/bin will never be empty.
The rustup binary will always be there, right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FranciscoTGouveia The original intention at least is that on Unix we should remove the rustup shims in one go; on Windows we remove all the rustup shims except the potentially current running binary which then gets removed in another process.

When the other review comments are addressed I think we can do a final round of check about this.

Comment thread src/cli/self_update/unix.rs Outdated
Comment thread tests/suite/cli_self_upd.rs Outdated
Comment thread src/cli/self_update.rs Outdated
Comment thread src/cli/self_update/unix.rs Outdated
Comment thread src/cli/self_update/windows.rs Outdated
.spawn()
.context(CliError::WindowsUninstallMadness)?;

// clean up PATH and dir
Copy link
Copy Markdown
Member

@rami3l rami3l May 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Maybe extract this as a helper function?

View changes since the review

Comment thread src/cli/self_update.rs Outdated
Comment thread src/cli/self_update/windows.rs Outdated
Comment thread src/cli/self_update/windows.rs Outdated
Comment thread src/cli/self_update/windows.rs Outdated
Comment thread src/cli/self_update.rs Outdated
Comment thread src/cli/self_update.rs Outdated
Cloud0310 added 3 commits May 20, 2026 21:41
fix rust-lang#285
This contains:
- initial logic for detecting $CARGO_HOME/bin is empty
- refactor`delete_rustup_and_cargo_home` to `delete_rustup_bin`.
  TODOs:
- add further test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stop nuking $CARGO_HOME (~/.cargo) on rustup self uninstall

4 participants