Skip to content

refactor(install): decouple helpers from process then re-use the resolution result - #5096

Open
Cloud0310 wants to merge 7 commits into
rust-lang:mainfrom
Cloud0310:install-state
Open

Cloud0310 wants to merge 7 commits into
rust-lang:mainfrom
Cloud0310:install-state

Conversation

@Cloud0310

Copy link
Copy Markdown
Contributor

#5091 was not a complete decouple of Process's state from the related install/uninstall helpers.
So, this PR does:

  • renaming relevant fucntions for better expressing what they're doing
  • removing unnessary Cow usage of cargo_home_str_with_home, cargo_home_str, as the caller immediately constructs String
  • decouple Process' states, e.g. cargo_home and other, allowing for re-using the resolution result.
  • dedup remove_legacy_source_command, as the same logic is already done in do_remove_from_path

In the meantime, this the first of a series of refactors around uninstall/install/self-replacing logic.

@rustbot

rustbot commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

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.

@djc djc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Most of this looks fine to me.

Decoupling helpers from Process seems pretty messy for ostensibly very limited benefit.

View changes since this review

@rami3l

rami3l commented Sep 21, 2026

Copy link
Copy Markdown
Member

@djc I would like to provide some extra context regarding this part of the changes: it has been a follow-up of my request #5091 (comment) in a previous attempt of decoupling the rcfile-related logic from &Process.

This is needed because the new uninstallation logic will attempt to remove the rcfile entries from both the CARGO_HOME/bin and CARGO_BIN_HOME installations in #5056, and thus these paths can no longer be injected from &Process anymore.

Comment thread src/cli/self_update.rs
Comment on lines +1095 to +1118
#[cfg(unix)]
{
let home_dir = process.home_dir();
for sh in shell::get_available_shells(process) {
let source_cmd = sh.source_string(cargo_home, home_dir.as_deref())?;
// Check more files for cleanup than normally are updated.
do_remove_from_path(
&source_cmd,
&sh.rc_candidates(home_dir.as_deref(), process),
)?;
}
unix::remove_legacy_paths(
cargo_home,
home_dir.as_deref(),
&shell::legacy_paths(process).collect::<Vec<_>>(),
)?;
}
#[cfg(windows)]
{
let environment = process
.registry_environment_key()
.context("Failed opening Environment key")?;
do_remove_from_path(cargo_home, &environment)?;
}

@rami3l rami3l Sep 21, 2026

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.

Nit: You can use cfg_select!{} for this.

View changes since the review

Comment thread src/cli/self_update.rs
format!(
pre_uninstall_msg!(),
cargo_home = display_cargo_home(process)?
cargo_home = display_cargo_home(&cargo_home, process.home_dir().as_deref())

@rami3l rami3l Sep 21, 2026

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.

Question: Judging from the immediate result, it seems like this call begs to be a new type declaration like the following...

struct CargoHomeDisplay { cargo_home: ..., home_dir: ... }
impl Display for CargoHomeDisplay { ... }

However I am wondering how you are planning to fit the current refactoring change into the final implementation of #5056. Ideally the APIs should stay as close as possible to the final shape. Would you mind elaborating a bit on that point (as well as whether you think the above suggestion makes sense WRT your final goal)? 🙏

View changes since the review

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.

4 participants