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.
|
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 :)
| } | ||
|
|
||
| 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.
| 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. |
afd4a48 to
6e27966
Compare
|
@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 🙏 |
2415ba4 to
5850b3e
Compare
fix: preserve CARGO_HOME during Windows uninstall
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.