Skip to content

Commit 8045aeb

Browse files
committed
Do not install toolchain on rustup show * and rustup --version
1 parent 3ac5076 commit 8045aeb

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

src/cli/rustup_mode.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub fn main() -> Result<utils::ExitCode> {
8585
cfg.set_toolchain_override(&t[1..]);
8686
}
8787

88-
let toolchain = cfg.find_or_install_override_toolchain_or_default(&cwd)?.0;
88+
let toolchain = cfg.find_or_install_override_toolchain_or_default(&cwd, false)?.0;
8989

9090
Ok(toolchain.rustc_version())
9191
}
@@ -1051,7 +1051,7 @@ fn show(cfg: &Cfg) -> Result<utils::ExitCode> {
10511051
let cwd = utils::current_dir()?;
10521052
let installed_toolchains = cfg.list_toolchains()?;
10531053
// XXX: we may want a find_without_install capability for show.
1054-
let active_toolchain = cfg.find_or_install_override_toolchain_or_default(&cwd);
1054+
let active_toolchain = cfg.find_or_install_override_toolchain_or_default(&cwd, false);
10551055

10561056
// active_toolchain will carry the reason we don't have one in its detail.
10571057
let active_targets = if let Ok(ref at) = active_toolchain {
@@ -1176,7 +1176,7 @@ fn show(cfg: &Cfg) -> Result<utils::ExitCode> {
11761176

11771177
fn show_active_toolchain(cfg: &Cfg) -> Result<utils::ExitCode> {
11781178
let cwd = utils::current_dir()?;
1179-
match cfg.find_or_install_override_toolchain_or_default(&cwd) {
1179+
match cfg.find_or_install_override_toolchain_or_default(&cwd, false) {
11801180
Err(crate::Error(crate::ErrorKind::ToolchainNotSelected, _)) => {}
11811181
Err(e) => return Err(e.into()),
11821182
Ok((toolchain, reason)) => {
@@ -1337,7 +1337,7 @@ fn explicit_or_dir_toolchain<'a>(cfg: &'a Cfg, m: &ArgMatches<'_>) -> Result<Too
13371337
}
13381338

13391339
let cwd = utils::current_dir()?;
1340-
let (toolchain, _) = cfg.toolchain_for_dir(&cwd)?;
1340+
let (toolchain, _) = cfg.find_or_install_override_toolchain_or_default(&cwd, true)?;
13411341

13421342
Ok(toolchain)
13431343
}

src/config.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ impl Cfg {
409409
}
410410

411411
pub fn which_binary(&self, path: &Path, binary: &str) -> Result<Option<PathBuf>> {
412-
let (toolchain, _) = self.find_or_install_override_toolchain_or_default(path)?;
412+
let (toolchain, _) = self.find_or_install_override_toolchain_or_default(path, true)?;
413413
Ok(Some(toolchain.binary_file(binary)))
414414
}
415415

@@ -620,6 +620,7 @@ impl Cfg {
620620
pub fn find_or_install_override_toolchain_or_default(
621621
&self,
622622
path: &Path,
623+
install: bool,
623624
) -> Result<(Toolchain<'_>, Option<OverrideReason>)> {
624625
fn components_exist(
625626
distributable: &DistributableToolchain<'_>,
@@ -699,7 +700,7 @@ impl Cfg {
699700
let targets: Vec<_> = targets.iter().map(AsRef::as_ref).collect();
700701

701702
let distributable = DistributableToolchain::new(&toolchain)?;
702-
if !toolchain.exists() || !components_exist(&distributable, &components, &targets)?
703+
if install && (!toolchain.exists() || !components_exist(&distributable, &components, &targets)?)
703704
{
704705
distributable.install_from_dist(true, false, &components, &targets, profile)?;
705706
}
@@ -789,15 +790,8 @@ impl Cfg {
789790
})
790791
}
791792

792-
pub fn toolchain_for_dir(
793-
&self,
794-
path: &Path,
795-
) -> Result<(Toolchain<'_>, Option<OverrideReason>)> {
796-
self.find_or_install_override_toolchain_or_default(path)
797-
}
798-
799793
pub fn create_command_for_dir(&self, path: &Path, binary: &str) -> Result<Command> {
800-
let (ref toolchain, _) = self.toolchain_for_dir(path)?;
794+
let (ref toolchain, _) = self.find_or_install_override_toolchain_or_default(path, true)?;
801795

802796
if let Some(cmd) = self.maybe_do_cargo_fallback(toolchain, binary)? {
803797
Ok(cmd)

0 commit comments

Comments
 (0)