Skip to content

self_update: Ensure profile set on self-update #2050

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

Merged
merged 1 commit into from
Oct 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1582,13 +1582,31 @@ pub fn run_update(setup_path: &Path) -> Result<()> {
process::exit(0);
}

/// Ensure that the configuration is good after a self-update
///
/// Currently the only thing we do is ensure that a profile is set
/// since that could mess things up otherwise, and we don't really
/// want to do a full metadata update for that. There are potentially
/// legitimate reasons for a user to unset profile though so we only
/// set it on updates rather than simply ensuring we always have a
/// profile set in `Cfg::get_profile()`
fn ensure_config_good() -> Result<()> {
let cfg = common::set_globals(false, true)?;
if cfg.get_profile()?.is_none() {
cfg.set_profile(Profile::default_name())?;
}

Ok(())
}

/// This function is as the final step of a self-upgrade. It replaces
/// `CARGO_HOME`/bin/rustup with the running exe, and updates the the
/// links to it. On windows this will run *after* the original
/// rustup process exits.
#[cfg(unix)]
pub fn self_replace() -> Result<()> {
install_bins()?;
ensure_config_good()?;

Ok(())
}
Expand All @@ -1597,6 +1615,7 @@ pub fn self_replace() -> Result<()> {
pub fn self_replace() -> Result<()> {
wait_for_parent()?;
install_bins()?;
ensure_config_good()?;

Ok(())
}
Expand Down