-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix: stop deleting $CARGO_HOME during uninstall #4861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Cloud0310
wants to merge
9
commits into
rust-lang:main
Choose a base branch
from
Cloud0310:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+197
−33
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
754b48d
refactor: rename delete_rustup_and_cargo_home to clean_cargo_bin
Cloud0310 f2bfa78
refactor(cli/self-update): move `unix::clean_cargo_bin()` to parent m…
Cloud0310 ff8b3b5
refactor: pass PATH cleanup to `clean_cargo_bin`
Cloud0310 58b9416
doc: add uninstall process overall docstring
Cloud0310 0117fd0
fix: preserve CARGO_HOME during uninstall
Cloud0310 b6be474
fix: remove rustup proxy links during uninstall
Cloud0310 b67b25a
test: cover cargo bin removal during uninstall
Cloud0310 bb836d7
test: cover cargo bin PATH cleanup during uninstall
Cloud0310 0677697
test: cover Windows cargo bin cleanup during uninstall
Cloud0310 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -348,16 +348,18 @@ fn has_windows_sdk_libs(process: &Process) -> bool { | |
| false | ||
| } | ||
|
|
||
| /// Run by rustup-gc-$num.exe to delete CARGO_HOME | ||
| /// Run by rustup-gc-$num.exe to delete rustup binary | ||
|
Cloud0310 marked this conversation as resolved.
|
||
| #[tracing::instrument(level = "trace")] | ||
| pub fn complete_windows_uninstall(process: &Process) -> Result<utils::ExitCode> { | ||
| use std::process::Stdio; | ||
|
|
||
| wait_for_parent()?; | ||
|
|
||
| // Now that the parent has exited there are hopefully no more files open in CARGO_HOME | ||
| let cargo_home = process.cargo_home()?; | ||
| utils::remove_dir("cargo_home", &cargo_home)?; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can possibly further refine the history by splitting "refactor: pass PATH cleanup to clean_cargo_bin" into two commits:
|
||
| let no_modify_path = process.var_os(GC_MODIFY_PATH).as_deref() != Some(OsStr::new("1")); | ||
|
|
||
| // Clean up CARGO_HOME/bin if it's empty now | ||
| // On success, also remove it from $PATH. | ||
| super::clean_cargo_bin(no_modify_path, process)?; | ||
|
|
||
| // Now, run a *system* binary to inherit the DELETE_ON_CLOSE | ||
| // handle to *this* process, then exit. The OS will delete the gc | ||
|
|
@@ -644,9 +646,9 @@ pub(crate) fn self_replace(process: &Process) -> Result<utils::ExitCode> { | |
| Ok(utils::ExitCode(0)) | ||
| } | ||
|
|
||
| // The last step of uninstallation is to delete *this binary*, | ||
| // rustup.exe and the CARGO_HOME that contains it. On Unix, this | ||
| // works fine. On Windows you can't delete files while they are open, | ||
| // The last step of uninstallation is to delete *this binary*, rustup.exe. | ||
| // On Unix, this works fine. | ||
| // On Windows you can't delete files while they are open, | ||
| // like when they are running. | ||
| // | ||
| // Here's what we're going to do: | ||
|
|
@@ -659,7 +661,7 @@ pub(crate) fn self_replace(process: &Process) -> Result<utils::ExitCode> { | |
| // processes created with the option to inherit handles | ||
| // will also keep them open. | ||
| // - Run the gc exe, which waits for the original rustup.exe | ||
| // process to close, then deletes CARGO_HOME. This process | ||
| // process to close, then deletes rustup.exe. This process | ||
| // has inherited a FILE_FLAG_DELETE_ON_CLOSE handle to itself. | ||
| // - Finally, spawn yet another system binary with the inherit handles | ||
| // flag, so *it* inherits the FILE_FLAG_DELETE_ON_CLOSE handle to | ||
|
|
@@ -674,7 +676,7 @@ pub(crate) fn self_replace(process: &Process) -> Result<utils::ExitCode> { | |
| // | ||
| // .. augmented with this SO answer | ||
| // https://stackoverflow.com/questions/10319526/understanding-a-self-deleting-program-in-c | ||
| pub(crate) fn delete_rustup_and_cargo_home(process: &Process) -> Result<()> { | ||
| pub(crate) fn clean_cargo_bin(no_modify_path: bool, process: &Process) -> Result<()> { | ||
| use std::io; | ||
| use std::ptr; | ||
| use std::thread; | ||
|
|
@@ -734,6 +736,7 @@ pub(crate) fn delete_rustup_and_cargo_home(process: &Process) -> Result<()> { | |
| }; | ||
|
|
||
| Command::new(gc_exe) | ||
| .env(GC_MODIFY_PATH, if no_modify_path { "0" } else { "1" }) | ||
| .spawn() | ||
| .context(CliError::WindowsUninstallMadness)?; | ||
|
|
||
|
|
@@ -749,6 +752,10 @@ pub(crate) fn delete_rustup_and_cargo_home(process: &Process) -> Result<()> { | |
| Ok(()) | ||
| } | ||
|
|
||
| // The rustup-gc executable cannot accept normal function call here, | ||
| // so we use env var here, notifying it if we need to remove $CARGO_HOME/bin from $PATH | ||
| const GC_MODIFY_PATH: &str = "RUSTUP_GC_MODIFY_PATH"; | ||
|
|
||
| #[cfg(any(test, feature = "test"))] | ||
| pub fn get_path() -> Result<Option<Value>> { | ||
| USER_PATH.get() | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.