Skip to content

Commit 2ebfa92

Browse files
committed
Move install_from_dist_if_not_installed to DistributableToolchain
1 parent 12a63f3 commit 2ebfa92

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

src/cli/rustup_mode.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,8 @@ fn default_(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
743743
let toolchain = cfg.get_toolchain(toolchain, false)?;
744744

745745
let status = if !toolchain.is_custom() {
746-
Some(toolchain.install_from_dist_if_not_installed()?)
746+
let distributable = DistributableToolchain::new(&toolchain)?;
747+
Some(distributable.install_from_dist_if_not_installed()?)
747748
} else if !toolchain.exists() {
748749
return Err(ErrorKind::ToolchainNotInstalled(toolchain.name().to_string()).into());
749750
} else {
@@ -1251,7 +1252,8 @@ fn override_add(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
12511252
let toolchain = cfg.get_toolchain(toolchain, false)?;
12521253

12531254
let status = if !toolchain.is_custom() {
1254-
Some(toolchain.install_from_dist_if_not_installed()?)
1255+
let distributable = DistributableToolchain::new(&toolchain)?;
1256+
Some(distributable.install_from_dist_if_not_installed()?)
12551257
} else if !toolchain.exists() {
12561258
return Err(ErrorKind::ToolchainNotInstalled(toolchain.name().to_string()).into());
12571259
} else {

src/toolchain.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -184,22 +184,6 @@ impl<'a> Toolchain<'a> {
184184
}
185185
}
186186

187-
// Distributable only. Installed or not installed.
188-
pub fn install_from_dist_if_not_installed(&self) -> Result<UpdateStatus> {
189-
let update_hash = self.update_hash()?;
190-
self.install_if_not_installed(InstallMethod::Dist(
191-
&self.desc()?,
192-
self.cfg.get_profile()?,
193-
update_hash.as_ref().map(|p| &**p),
194-
self.download_cfg(),
195-
false,
196-
false,
197-
false,
198-
None,
199-
&[],
200-
&[],
201-
))
202-
}
203187
// Custom only
204188
pub fn is_custom(&self) -> bool {
205189
ToolchainDesc::from_str(&self.name).is_err()
@@ -757,6 +741,23 @@ impl<'a> DistributableToolchain<'a> {
757741
))
758742
}
759743

744+
// Installed or not installed.
745+
pub fn install_from_dist_if_not_installed(&self) -> Result<UpdateStatus> {
746+
let update_hash = self.0.update_hash()?;
747+
self.0.install_if_not_installed(InstallMethod::Dist(
748+
&self.0.desc()?,
749+
self.0.cfg.get_profile()?,
750+
update_hash.as_ref().map(|p| &**p),
751+
self.0.download_cfg(),
752+
false,
753+
false,
754+
false,
755+
None,
756+
&[],
757+
&[],
758+
))
759+
}
760+
760761
// Installed only.
761762
pub fn list_components(&self) -> Result<Vec<ComponentStatus>> {
762763
if !self.0.exists() {

0 commit comments

Comments
 (0)