Skip to content

Commit

Permalink
rustup: Prevent setting an invalid default host
Browse files Browse the repository at this point in the history
Perform similar checks to when resolving toolchains in order to
reduce the possibility that the configuration will end up with an
unusable default-host value.  This finally addresses the initial
point in #745 and thus fixes it.

Signed-off-by: Daniel Silverstone <[email protected]>
  • Loading branch information
kinnison committed Jan 14, 2019
1 parent 0bb2cde commit 49a9cec
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/rustup/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 478,20 @@ impl Cfg {
}

pub fn set_default_host_triple(&self, host_triple: &str) -> Result<()> {
if dist::PartialTargetTriple::from_str(host_triple).is_none() {
if let Some(host) = dist::PartialTargetTriple::from_str(host_triple) {
host.arch.ok_or_else(|| {
format!(
"Provided host '{}' did not specify a CPU architecture",
host_triple
)
})?;
host.os.ok_or_else(|| {
format!(
"Provided host '{}' did not specify an operating system",
host_triple
)
})?;
} else {
return Err("Invalid host triple".into());
}
self.settings_file.with_mut(|s| {
Expand Down
12 changes: 12 additions & 0 deletions tests/cli-rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 905,18 @@ fn set_default_host_invalid_triple() {
});
}

// #745
#[test]
fn set_default_host_invalid_triple_valid_partial() {
setup(&|config| {
expect_err(
config,
&["rustup", "set", "default-host", "x86_64-msvc"],
"error: Provided host 'x86_64-msvc' did not specify an operating system",
);
});
}

// #422
#[test]
fn update_doesnt_update_non_tracking_channels() {
Expand Down

0 comments on commit 49a9cec

Please sign in to comment.