fix!: stop deleting $CARGO_HOME during uninstall#4861
Conversation
|
I think I may need more tests against this PR, this includes:
Should there be more tests? Please let me know @FranciscoTGouveia @rami3l . |
|
I've add more tests about the PR here. Please review. |
4a4880a to
971dffa
Compare
Avoid removing $CARGO_HOME when running uninstall cleanup. Combine all follow-up work for PR rust-lang#4861: - keep $CARGO_HOME/bin when it is non-empty - cover cargo bin cleanup behavior in uninstall tests - update uninstall cleanup comments and related docs - rename cleanup internals for clearer intent
Avoid removing $CARGO_HOME when running uninstall cleanup. Combine all follow-up work for PR rust-lang#4861: - keep $CARGO_HOME/bin when it is non-empty - cover cargo bin cleanup behavior in uninstall tests - update uninstall cleanup comments and related docs - rename cleanup internals for clearer intent
This comment has been minimized.
This comment has been minimized.
Avoid removing $CARGO_HOME when running uninstall cleanup. Combine all follow-up work for PR rust-lang#4861: - keep $CARGO_HOME/bin when it is non-empty - cover cargo bin cleanup behavior in uninstall tests - update uninstall cleanup comments and related docs - rename cleanup internals for clearer intent
Avoid removing $CARGO_HOME when running uninstall cleanup. Combine all follow-up work for PR rust-lang#4861: - keep $CARGO_HOME/bin when it is non-empty - cover cargo bin cleanup behavior in uninstall tests - update uninstall cleanup comments and related docs - rename cleanup internals for clearer intent
Avoid removing $CARGO_HOME when running uninstall cleanup. Combine all follow-up work for PR rust-lang#4861: - keep $CARGO_HOME/bin when it is non-empty - cover cargo bin cleanup behavior in uninstall tests - update uninstall cleanup comments and related docs - rename cleanup internals for clearer intent
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
67d8653 to
9f17fce
Compare
This comment has been minimized.
This comment has been minimized.
|
The splitting is done. Do I need further splitting with tests? |
There was a problem hiding this comment.
@Cloud0310 It is looking better, but some rework remains to be done. Especially, the 3rd commit (which used to be the 2nd commit in the last version) is still not boring enough.
The splitting is done. Do I need further splitting with tests?
If so, it could be more splitted into a) updated expected values, b) new tests upon keeping $CARGO_HOME.
Please perform the split you mentioned above as well.
Many thanks in advance :)
| info!("removed cargo bin from $PATH"); | ||
| } | ||
|
|
||
| info!("removed empty cargo bin"); |
There was a problem hiding this comment.
Nit: The way you refer to the bindir is not consistent both in this function and elsewhere:
cargo bincargo bin `{cargo_bin_path}`cargo bin directory `{cargo_bin_path}`
I suggest using the final one consistently.
| // 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)?; | ||
| // Now that the parent has exited, rustup.exe is hopefully no longer open. |
There was a problem hiding this comment.
This new hunk has the same contents as unix::clean_cargo_bin() except the let no_modify_path line; consider further polishing the refactoring process by first moving unix::clean_cargo_bin() to the parent module and inline your current delete_cargo_bin() over there (it should have a single caller by then so the introduction of this new function delete_cargo_bin() is unnecessary).
There was a problem hiding this comment.
@Cloud0310 Please delete the function delete_cargo_bin. As previously discussed, unix::clean_cargo_bin() should be moved to the parent module that contains logic common to both Windows and Unix (which includes the logic of delete_cargo_bin which is not repeated anywhere else); in Windows we use a platform specific wrapper to wrap that function in the windows module.
| } | ||
|
|
||
| pub(crate) fn clean_cargo_bin(process: &Process) -> Result<()> { | ||
| pub(crate) fn clean_cargo_bin(process: &Process, no_modify_path: bool) -> Result<()> { |
There was a problem hiding this comment.
Nit: change the argument order (for this and other functions with the added argument), to have the more "interesting"/rare/specific argument before the less interesting/more common/less specific process argument.
| use anyhow::{Context, Result, bail}; | ||
| use tracing::{error, warn}; | ||
|
|
||
| use super::delete_cargo_bin; |
There was a problem hiding this comment.
Nit: this should be included in the existing super:: import, below.
There was a problem hiding this comment.
@djc I'm not quite sure what you are trying to say here, I assume you mean "in a first commit merge those in two groups of imports super::{...} and crate::{...}, then introduce the new import in the respective group"? Because in this file the imports are not grouped yet.
There was a problem hiding this comment.
I mean that this is adding a use super::delete_cargo_bin; when there is already a use super::some_other_thing;.
There was a problem hiding this comment.
@djc Okay, so we should put the single-level imports like this use super::{delete_cargo_bin, some_other_thing};
| utils::remove_dir("cargo_home", &cargo_home) | ||
| // Clean up CARGO_HOME/bin, if it's empty now | ||
| // On success, remove it from $PATH | ||
| delete_cargo_bin(cargo_bin_path, no_modify_path, process) |
There was a problem hiding this comment.
It is unclear to me why there are separate commits for the Unix and Windows paths? It seems to me like these should be in the same commit.
| let diriter = fs::read_dir(&cargo_home).map_err(|e| CliError::ReadDirError { | ||
| p: cargo_home.clone(), | ||
| source: e, | ||
| })?; | ||
| for dirent in diriter { | ||
| let dirent = dirent.map_err(|e| CliError::ReadDirError { | ||
| p: cargo_home.clone(), | ||
| source: e, | ||
| })?; | ||
| if dirent.file_name().to_str() != Some("bin") { | ||
| if dirent.path().is_dir() { | ||
| utils::remove_dir("cargo_home", &dirent.path())?; | ||
| } else { | ||
| utils::remove_file("cargo_home", &dirent.path())?; | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
It is not clear from reviewing this (presumably Unix-only) commit why this (presumably platform-independent) logic could be removed.
|
|
||
| use super::super::errors::CliError; | ||
| use super::common; | ||
| use super::delete_cargo_bin; |
There was a problem hiding this comment.
Nit: use existing import.
| Ok(utils::ExitCode(0)) | ||
| } | ||
|
|
||
| const GC_MODIFY_PATH: &str = "RUSTUP_GC_MODIFY_PATH"; |
There was a problem hiding this comment.
Perhaps this should be introduced independently to make it more clear why it is introduced/what it's purpose is? (It should be defined below all callers.)
| /// Uninstall process: | ||
| /// 1. Remove rustup home. | ||
| /// 2. Clean up rustup tool proxies. | ||
| /// 3. Remove rustup binary file. | ||
| /// 4. Try to clean up $CARGO_HOME/bin if it's empty. | ||
| /// 5. Upon successfully removing $CARGO_HOME/bin, clean up $PATH. |
There was a problem hiding this comment.
Suggest introducing this in a separate first commit, and then updating it in each commit (where necessary) as a way of documenting what is changed.
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
fix: preserve CARGO_HOME during Windows uninstall
|
@Cloud0310 Since your PR needs more work, I've marked this PR as draft. Please address or at least respond to all open threads before marking this PR as "ready for review" again, at which point the team will return for another round of review, thanks 🙏 |
fix #285
This PR fix the cargo bin nuke and the path removing possilble toutoc issue.
Here's the implementation details:
This prevents
rustup self uninstallfrom nuking out the$CARGO_HOME/binand possible toctou problem of removing up the path.