From a9d0c67d4aaa74863fbd56962cb83e2e207f607d Mon Sep 17 00:00:00 2001 From: kellda <59569234+kellda@users.noreply.github.com> Date: Thu, 11 Feb 2021 11:08:51 +0100 Subject: [PATCH] Do not install toolchain on `rustup show *` and `rustup --version` --- src/cli/rustup_mode.rs | 10 ++++++---- src/config.rs | 16 ++++++---------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index 23b80c1256..0e2f2662d1 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -85,7 +85,9 @@ pub fn main() -> Result { cfg.set_toolchain_override(&t[1..]); } - let toolchain = cfg.find_or_install_override_toolchain_or_default(&cwd)?.0; + let toolchain = cfg + .find_or_install_override_toolchain_or_default(&cwd, false)? + .0; Ok(toolchain.rustc_version()) } @@ -1051,7 +1053,7 @@ fn show(cfg: &Cfg) -> Result { let cwd = utils::current_dir()?; let installed_toolchains = cfg.list_toolchains()?; // XXX: we may want a find_without_install capability for show. - let active_toolchain = cfg.find_or_install_override_toolchain_or_default(&cwd); + let active_toolchain = cfg.find_or_install_override_toolchain_or_default(&cwd, false); // active_toolchain will carry the reason we don't have one in its detail. let active_targets = if let Ok(ref at) = active_toolchain { @@ -1176,7 +1178,7 @@ fn show(cfg: &Cfg) -> Result { fn show_active_toolchain(cfg: &Cfg) -> Result { let cwd = utils::current_dir()?; - match cfg.find_or_install_override_toolchain_or_default(&cwd) { + match cfg.find_or_install_override_toolchain_or_default(&cwd, false) { Err(crate::Error(crate::ErrorKind::ToolchainNotSelected, _)) => {} Err(e) => return Err(e.into()), Ok((toolchain, reason)) => { @@ -1337,7 +1339,7 @@ fn explicit_or_dir_toolchain<'a>(cfg: &'a Cfg, m: &ArgMatches<'_>) -> Result Result> { - let (toolchain, _) = self.find_or_install_override_toolchain_or_default(path)?; + let (toolchain, _) = self.find_or_install_override_toolchain_or_default(path, true)?; Ok(Some(toolchain.binary_file(binary))) } @@ -620,6 +620,7 @@ impl Cfg { pub fn find_or_install_override_toolchain_or_default( &self, path: &Path, + install: bool, ) -> Result<(Toolchain<'_>, Option)> { fn components_exist( distributable: &DistributableToolchain<'_>, @@ -699,7 +700,9 @@ impl Cfg { let targets: Vec<_> = targets.iter().map(AsRef::as_ref).collect(); let distributable = DistributableToolchain::new(&toolchain)?; - if !toolchain.exists() || !components_exist(&distributable, &components, &targets)? + if install + && (!toolchain.exists() + || !components_exist(&distributable, &components, &targets)?) { distributable.install_from_dist(true, false, &components, &targets, profile)?; } @@ -789,15 +792,8 @@ impl Cfg { }) } - pub fn toolchain_for_dir( - &self, - path: &Path, - ) -> Result<(Toolchain<'_>, Option)> { - self.find_or_install_override_toolchain_or_default(path) - } - pub fn create_command_for_dir(&self, path: &Path, binary: &str) -> Result { - let (ref toolchain, _) = self.toolchain_for_dir(path)?; + let (ref toolchain, _) = self.find_or_install_override_toolchain_or_default(path, true)?; if let Some(cmd) = self.maybe_do_cargo_fallback(toolchain, binary)? { Ok(cmd)