Skip to content

Commit 6a04850

Browse files
committed
Port install_from_dist to DistributableToolchain
1 parent 250b02d commit 6a04850

File tree

5 files changed

+42
-38
lines changed

5 files changed

+42
-38
lines changed

src/cli/rustup_mode.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::topical_doc;
88
use clap::{App, AppSettings, Arg, ArgGroup, ArgMatches, Shell, SubCommand};
99
use rustup::dist::dist::{PartialTargetTriple, PartialToolchainDesc, Profile, TargetTriple};
1010
use rustup::dist::manifest::Component;
11+
use rustup::toolchain::DistributableToolchain;
1112
use rustup::utils::utils::{self, ExitCode};
1213
use rustup::Notification;
1314
use rustup::{command, Cfg, ComponentStatus, Toolchain};
@@ -840,7 +841,8 @@ fn update(cfg: &mut Cfg, m: &ArgMatches<'_>) -> Result<()> {
840841
.values_of("targets")
841842
.map(|v| v.collect())
842843
.unwrap_or_else(Vec::new);
843-
Some(toolchain.install_from_dist(
844+
let distributable = DistributableToolchain::new(&toolchain)?;
845+
Some(distributable.install_from_dist(
844846
m.is_present("force"),
845847
m.is_present("allow-downgrade"),
846848
&components,

src/cli/self_update.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use crate::errors::*;
3535
use crate::markdown::md;
3636
use crate::term2;
3737
use rustup::dist::dist::{self, Profile, TargetTriple};
38+
use rustup::toolchain::DistributableToolchain;
3839
use rustup::utils::utils;
3940
use rustup::utils::Notification;
4041
use rustup::{Cfg, UpdateStatus};
@@ -787,7 +788,8 @@ fn maybe_install_rust(
787788
if toolchain.exists() {
788789
warn!("Updating existing toolchain, profile choice will be ignored");
789790
}
790-
let status = toolchain.install_from_dist(true, false, components, targets)?;
791+
let distributable = DistributableToolchain::new(&toolchain)?;
792+
let status = distributable.install_from_dist(true, false, components, targets)?;
791793
cfg.set_default(toolchain_str)?;
792794
println!();
793795
common::show_channel_update(&cfg, toolchain_str, Ok(status))?;

src/config.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::errors::*;
1414
use crate::fallback_settings::FallbackSettings;
1515
use crate::notifications::*;
1616
use crate::settings::{Settings, SettingsFile, DEFAULT_METADATA_VERSION};
17-
use crate::toolchain::{Toolchain, UpdateStatus};
17+
use crate::toolchain::{DistributableToolchain, Toolchain, UpdateStatus};
1818
use crate::utils::utils;
1919

2020
#[derive(Debug)]
@@ -510,7 +510,8 @@ impl Cfg {
510510
ErrorKind::ToolchainNotInstalled(toolchain.name().to_string()).into(),
511511
);
512512
}
513-
toolchain.install_from_dist(true, false, &[], &[])?;
513+
let distributable = DistributableToolchain::new(&toolchain)?;
514+
distributable.install_from_dist(true, false, &[], &[])?;
514515
}
515516
Ok((toolchain, reason))
516517
} else {
@@ -568,15 +569,16 @@ impl Cfg {
568569

569570
// Update toolchains and collect the results
570571
let channels = channels.map(|(n, t)| {
571-
let t = t.and_then(|t| {
572-
let t = t.install_from_dist(force_update, false, &[], &[]);
573-
if let Err(ref e) = t {
572+
let st = t.and_then(|t| {
573+
let distributable = DistributableToolchain::new(&t)?;
574+
let st = distributable.install_from_dist(force_update, false, &[], &[]);
575+
if let Err(ref e) = st {
574576
(self.notify_handler)(Notification::NonFatalError(e));
575577
}
576-
t
578+
st
577579
});
578580

579-
(n, t)
581+
(n, st)
580582
});
581583

582584
Ok(channels.collect())
@@ -620,7 +622,8 @@ impl Cfg {
620622
) -> Result<Command> {
621623
let toolchain = self.get_toolchain(toolchain, false)?;
622624
if install_if_missing && !toolchain.exists() {
623-
toolchain.install_from_dist(true, false, &[], &[])?;
625+
let distributable = DistributableToolchain::new(&toolchain)?;
626+
distributable.install_from_dist(true, false, &[], &[])?;
624627
}
625628

626629
if let Some(cmd) = self.maybe_do_cargo_fallback(&toolchain, binary)? {

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,5 @@ pub mod fallback_settings;
6262
mod install;
6363
mod notifications;
6464
pub mod settings;
65-
mod toolchain;
65+
pub mod toolchain;
6666
pub mod utils;

src/toolchain.rs

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

187-
// Distributable only. Not installed only?
188-
pub fn install_from_dist(
189-
&self,
190-
force_update: bool,
191-
allow_downgrade: bool,
192-
components: &[&str],
193-
targets: &[&str],
194-
) -> Result<UpdateStatus> {
195-
let update_hash = self.update_hash()?;
196-
let distributable = DistributableToolchain::new(&self)?;
197-
let old_date = distributable
198-
.get_manifest()
199-
.ok()
200-
.and_then(|m| m.map(|m| m.date));
201-
self.install(InstallMethod::Dist(
202-
&self.desc()?,
203-
self.cfg.get_profile()?,
204-
update_hash.as_ref().map(|p| &**p),
205-
self.download_cfg(),
206-
force_update,
207-
allow_downgrade,
208-
self.exists(),
209-
old_date.as_ref().map(|s| &**s),
210-
components,
211-
targets,
212-
))
213-
}
214187
// Distributable only. Installed or not installed.
215188
pub fn install_from_dist_if_not_installed(&self) -> Result<UpdateStatus> {
216189
let update_hash = self.update_hash()?;
@@ -900,4 +873,28 @@ impl<'a> DistributableToolchain<'a> {
900873

901874
manifestation.load_manifest()
902875
}
876+
877+
// Not installed only?
878+
pub fn install_from_dist(
879+
&self,
880+
force_update: bool,
881+
allow_downgrade: bool,
882+
components: &[&str],
883+
targets: &[&str],
884+
) -> Result<UpdateStatus> {
885+
let update_hash = self.0.update_hash()?;
886+
let old_date = self.get_manifest().ok().and_then(|m| m.map(|m| m.date));
887+
self.0.install(InstallMethod::Dist(
888+
&self.0.desc()?,
889+
self.0.cfg.get_profile()?,
890+
update_hash.as_ref().map(|p| &**p),
891+
self.0.download_cfg(),
892+
force_update,
893+
allow_downgrade,
894+
self.0.exists(),
895+
old_date.as_ref().map(|s| &**s),
896+
components,
897+
targets,
898+
))
899+
}
903900
}

0 commit comments

Comments
 (0)