Skip to content

Commit 088f2d8

Browse files
committed
self_update: Ensure profile set on self-update
Fixes: rust-lang#2045 Signed-off-by: Daniel Silverstone <[email protected]>
1 parent b9e968b commit 088f2d8

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/cli/self_update.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,13 +1582,31 @@ pub fn run_update(setup_path: &Path) -> Result<()> {
15821582
process::exit(0);
15831583
}
15841584

1585+
/// Ensure that the configuration is good after a self-update
1586+
///
1587+
/// Currently the only thing we do is ensure that a profile is set
1588+
/// since that could mess things up otherwise, and we don't really
1589+
/// want to do a full metadata update for that. There are potentially
1590+
/// legitimate reasons for a user to unset profile though so we only
1591+
/// set it on updates rather than simply ensuring we always have a
1592+
/// profile set in `Cfg::get_profile()`
1593+
fn ensure_config_good() -> Result<()> {
1594+
let cfg = common::set_globals(false, true)?;
1595+
if cfg.get_profile()?.is_none() {
1596+
cfg.set_profile(Profile::default_name())?;
1597+
}
1598+
1599+
Ok(())
1600+
}
1601+
15851602
/// This function is as the final step of a self-upgrade. It replaces
15861603
/// `CARGO_HOME`/bin/rustup with the running exe, and updates the the
15871604
/// links to it. On windows this will run *after* the original
15881605
/// rustup process exits.
15891606
#[cfg(unix)]
15901607
pub fn self_replace() -> Result<()> {
15911608
install_bins()?;
1609+
ensure_config_good()?;
15921610

15931611
Ok(())
15941612
}
@@ -1597,6 +1615,7 @@ pub fn self_replace() -> Result<()> {
15971615
pub fn self_replace() -> Result<()> {
15981616
wait_for_parent()?;
15991617
install_bins()?;
1618+
ensure_config_good()?;
16001619

16011620
Ok(())
16021621
}

0 commit comments

Comments
 (0)