Skip to content

Commit 5bc2a89

Browse files
majaharami3l
authored andcommitted
Pull out ensure_installed()
1 parent e569cb4 commit 5bc2a89

File tree

1 file changed

+40
-27
lines changed

1 file changed

+40
-27
lines changed

src/config.rs

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -684,38 +684,51 @@ impl Cfg {
684684
Ok((Toolchain::new(self, toolchain)?, reason))
685685
}
686686
Some(LocalToolchainName::Named(ToolchainName::Official(desc))) => {
687-
let components: Vec<_> = components.iter().map(AsRef::as_ref).collect();
688-
let targets: Vec<_> = targets.iter().map(AsRef::as_ref).collect();
689-
let toolchain = match DistributableToolchain::new(self, desc.clone()) {
690-
Err(RustupError::ToolchainNotInstalled(_)) => {
691-
DistributableToolchain::install(
692-
self,
693-
&desc,
694-
&components,
695-
&targets,
696-
profile.unwrap_or(Profile::Default),
697-
false,
698-
)?
699-
.1
700-
}
701-
Ok(mut distributable) => {
702-
if !distributable.components_exist(&components, &targets)? {
703-
distributable.update(
704-
&components,
705-
&targets,
706-
profile.unwrap_or(Profile::Default),
707-
)?;
708-
}
709-
distributable
710-
}
711-
Err(e) => return Err(e.into()),
712-
}
713-
.into();
687+
let toolchain = self.ensure_installed(desc, components, targets, profile)?;
714688
Ok((toolchain, reason))
715689
}
716690
}
717691
}
718692

693+
// Returns a Toolchain matching the given ToolchainDesc, installing it and
694+
// the given components and targets if they aren't already installed.
695+
fn ensure_installed(
696+
&self,
697+
toolchain: ToolchainDesc,
698+
components: Vec<String>,
699+
targets: Vec<String>,
700+
profile: Option<Profile>,
701+
) -> Result<Toolchain<'_>> {
702+
let components: Vec<_> = components.iter().map(AsRef::as_ref).collect();
703+
let targets: Vec<_> = targets.iter().map(AsRef::as_ref).collect();
704+
let toolchain = match DistributableToolchain::new(self, toolchain.clone()) {
705+
Err(RustupError::ToolchainNotInstalled(_)) => {
706+
DistributableToolchain::install(
707+
self,
708+
&toolchain,
709+
&components,
710+
&targets,
711+
profile.unwrap_or(Profile::Default),
712+
false,
713+
)?
714+
.1
715+
}
716+
Ok(mut distributable) => {
717+
if !distributable.components_exist(&components, &targets)? {
718+
distributable.update(
719+
&components,
720+
&targets,
721+
profile.unwrap_or(Profile::Default),
722+
)?;
723+
}
724+
distributable
725+
}
726+
Err(e) => return Err(e.into()),
727+
}
728+
.into();
729+
Ok(toolchain)
730+
}
731+
719732
/// Get the configured default toolchain.
720733
/// If none is configured, returns None
721734
/// If a bad toolchain name is configured, errors.

0 commit comments

Comments
 (0)