Skip to content

Commit 8fedaa2

Browse files
committed
feat(rustup-init): detect and warn about existing settings.toml
1 parent 56ffeec commit 8fedaa2

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

src/cli/self_update.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ pub(crate) async fn install(
512512
.map_or(false, |s| s == "yes")
513513
{
514514
check_existence_of_rustc_or_cargo_in_path(no_prompt, process)?;
515+
check_existence_of_settings_file(process)?;
515516
}
516517

517518
#[cfg(unix)]
@@ -643,6 +644,18 @@ fn check_existence_of_rustc_or_cargo_in_path(no_prompt: bool, process: &Process)
643644
Ok(())
644645
}
645646

647+
fn check_existence_of_settings_file(process: &Process) -> Result<()> {
648+
let rustup_dir = process.rustup_home()?;
649+
let settings_file_path = rustup_dir.join("settings.toml");
650+
if utils::path_exists(&settings_file_path) {
651+
warn!("It looks like you have an existing rustup settings file at:");
652+
warn!("{}", settings_file_path.display());
653+
warn!("Rustup will install the default toolchain as specified in the settings file,");
654+
warn!("instead of the one inferred from the default host triple.");
655+
}
656+
Ok(())
657+
}
658+
646659
fn pre_install_msg(no_modify_path: bool, process: &Process) -> Result<String> {
647660
let cargo_home = process.cargo_home()?;
648661
let cargo_home_bin = cargo_home.join("bin");

tests/suite/cli_inst_interactive.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,3 +579,40 @@ async fn install_non_installable_toolchain() {
579579
)
580580
.await;
581581
}
582+
583+
#[tokio::test]
584+
async fn install_warns_about_existing_settings_file() {
585+
let temp_dir = tempfile::Builder::new()
586+
.prefix("fakehome")
587+
.tempdir()
588+
.unwrap();
589+
// Create `settings.toml`
590+
let settings_file = temp_dir.path().join("settings.toml");
591+
raw::write_file(
592+
&settings_file,
593+
for_host!(
594+
r#"default_toolchain = "{}"
595+
profile = "default"
596+
version = "12""#
597+
),
598+
)
599+
.unwrap();
600+
let temp_dir_path = temp_dir.path().to_str().unwrap();
601+
602+
let cx = CliTestContext::new(Scenario::SimpleV2).await;
603+
let out = cx
604+
.config
605+
.run(
606+
"rustup-init",
607+
["-y", "--no-modify-path"],
608+
&[
609+
("RUSTUP_INIT_SKIP_PATH_CHECK", "no"),
610+
("RUSTUP_HOME", temp_dir_path),
611+
],
612+
)
613+
.await;
614+
assert!(out.ok);
615+
assert!(out
616+
.stderr
617+
.contains("It looks like you have an existing rustup settings file at:"));
618+
}

0 commit comments

Comments
 (0)