Skip to content
19 changes: 16 additions & 3 deletions src/cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use tracing_subscriber::{EnvFilter, Registry, reload::Handle};

use crate::{
config::Cfg,
dist::{TargetTriple, ToolchainDesc},
dist::{DistOptions, TargetTriple, ToolchainDesc},
errors::RustupError,
install::UpdateStatus,
install::{InstallMethod, UpdateStatus},
process::Process,
toolchain::{LocalToolchainName, Toolchain, ToolchainName},
utils,
Expand Down Expand Up @@ -215,7 +215,20 @@ pub(crate) async fn update_all_channels(
cfg: &Cfg<'_>,
force_update: bool,
) -> Result<utils::ExitCode> {
let toolchains = cfg.update_all_channels(force_update).await?;
let profile = cfg.get_profile()?;
let mut toolchains = Vec::new();
for (desc, distributable) in cfg.list_channels()? {
let options = DistOptions::new(&[], &[], &desc, profile, force_update, cfg)?
.for_update(&distributable, false);
let result = InstallMethod::Dist(options).install().await;

if let Err(e) = &result {
error!("{e}");
}

toolchains.push((desc, result));
}

let has_update_error = toolchains.iter().any(|(_, r)| r.is_err());
let exit_code = utils::ExitCode(if has_update_error { 1 } else { 0 });

Expand Down
35 changes: 15 additions & 20 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use crate::{
command, component_for_bin,
config::{ActiveSource, Cfg},
dist::{
AutoInstallMode, PartialToolchainDesc, Profile, TargetTriple,
AutoInstallMode, DistOptions, PartialToolchainDesc, Profile, TargetTriple,
download::DownloadCfg,
manifest::{Component, ComponentStatus},
},
Expand Down Expand Up @@ -960,26 +960,23 @@ async fn update(

let components = opts.component.iter().map(|s| &**s).collect::<Vec<_>>();
let targets = opts.target.iter().map(|s| &**s).collect::<Vec<_>>();
let dist_opts = DistOptions::new(
&components,
&targets,
&desc,
cfg.get_profile()?,
opts.force,
cfg,
)?;

let force = opts.force;
let allow_downgrade = opts.allow_downgrade;
let profile = cfg.get_profile()?;
let status = match DistributableToolchain::new(cfg, desc.clone()) {
Ok(mut d) => {
d.update_extra(&components, &targets, profile, force, allow_downgrade)
Ok(d) => {
InstallMethod::Dist(dist_opts.for_update(&d, opts.allow_downgrade))
.install()
.await?
}
Err(RustupError::ToolchainNotInstalled { .. }) => {
DistributableToolchain::install(
cfg,
&desc,
&components,
&targets,
profile,
force,
)
.await?
.0
DistributableToolchain::install(dist_opts).await?.0
}
Err(e) => Err(e)?,
};
Expand Down Expand Up @@ -1519,10 +1516,8 @@ async fn override_add(
Err(e @ RustupError::ToolchainNotInstalled { .. }) => match &toolchain_name {
ToolchainName::Custom(_) => Err(e)?,
ToolchainName::Official(desc) => {
let status =
DistributableToolchain::install(cfg, desc, &[], &[], cfg.get_profile()?, false)
.await?
.0;
let options = DistOptions::new(&[], &[], desc, cfg.get_profile()?, false, cfg)?;
let status = DistributableToolchain::install(options).await?.0;
writeln!(cfg.process.stdout().lock())?;
common::show_channel_update(
cfg,
Expand Down
25 changes: 10 additions & 15 deletions src/cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ use crate::{
markdown::md,
},
config::Cfg,
dist::{PartialToolchainDesc, Profile, TargetTriple, ToolchainDesc, download::DownloadCfg},
dist::{
DistOptions, PartialToolchainDesc, Profile, TargetTriple, ToolchainDesc,
download::DownloadCfg,
},
download::download_file,
errors::RustupError,
install::UpdateStatus,
install::{InstallMethod, UpdateStatus},
process::Process,
toolchain::{
DistributableToolchain, MaybeOfficialToolchainName, ResolvableToolchainName, Toolchain,
Expand Down Expand Up @@ -996,28 +999,20 @@ async fn maybe_install_rust(opts: InstallOpts<'_>, cfg: &mut Cfg<'_>) -> Result<
let (components, targets) = (opts.components, opts.targets);
let toolchain = opts.install(cfg)?;
if let Some(desc) = &toolchain {
let options = DistOptions::new(components, targets, desc, cfg.get_profile()?, true, cfg)?;
let status = if Toolchain::exists(cfg, &desc.into())? {
warn!("Updating existing toolchain, profile choice will be ignored");
// If we have a partial install we might not be able to read content here. We could:
// - fail and folk have to delete the partially present toolchain to recover
// - silently ignore it (and provide inconsistent metadata for reporting the install/update change)
// - delete the partial install and start over
// For now, we error.
let mut toolchain = DistributableToolchain::new(cfg, desc.clone())?;
toolchain
.update(components, targets, cfg.get_profile()?)
let toolchain = DistributableToolchain::new(cfg, desc.clone())?;
InstallMethod::Dist(options.for_update(&toolchain, false))
.install()
.await?
} else {
DistributableToolchain::install(
cfg,
desc,
components,
targets,
cfg.get_profile()?,
true,
)
.await?
.0
DistributableToolchain::install(options).await?.0
};

check_proxy_sanity(cfg.process, components, desc)?;
Expand Down
66 changes: 24 additions & 42 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ use std::str::FromStr;
use anyhow::{Context, Result, anyhow, bail};
use serde::Deserialize;
use thiserror::Error as ThisError;
use tokio_stream::StreamExt;
use tracing::{debug, error, info, trace, warn};

use crate::dist::AutoInstallMode;
use crate::{
cli::{common, self_update::SelfUpdateMode},
dist::{self, PartialToolchainDesc, Profile, TargetTriple, ToolchainDesc, temp},
dist::{
self, AutoInstallMode, DistOptions, PartialToolchainDesc, Profile, TargetTriple,
ToolchainDesc, temp,
},
errors::RustupError,
fallback_settings::FallbackSettings,
install::UpdateStatus,
install::{InstallMethod, UpdateStatus},
process::Process,
settings::{MetadataVersion, Settings, SettingsFile},
toolchain::{
Expand Down Expand Up @@ -788,28 +789,31 @@ impl<'a> Cfg<'a> {
}
let components: Vec<_> = components.iter().map(AsRef::as_ref).collect();
let targets: Vec<_> = targets.iter().map(AsRef::as_ref).collect();
let profile = match profile {
Some(profile) => profile,
None => self.get_profile()?,
};
let mut options = DistOptions::new(
&components,
&targets,
toolchain,
match profile {
Some(p) => p,
None => self.get_profile()?,
},
false,
self,
)?;

let (status, toolchain) = match DistributableToolchain::new(self, toolchain.clone()) {
Err(RustupError::ToolchainNotInstalled { .. }) => {
DistributableToolchain::install(
self,
toolchain,
&components,
&targets,
profile,
false,
)
.await?
DistributableToolchain::install(options).await?
}
Ok(mut distributable) => {
Ok(distributable) => {
if verbose {
info!("using existing install for {toolchain}");
}
let status = if !distributable.components_exist(&components, &targets)? {
distributable.update(&components, &targets, profile).await?
options.force = true;
InstallMethod::Dist(options.for_update(&distributable, false))
.install()
.await?
} else {
UpdateStatus::Unchanged
};
Expand Down Expand Up @@ -893,28 +897,6 @@ impl<'a> Cfg<'a> {
})
}

pub(crate) async fn update_all_channels(
&self,
force_update: bool,
) -> Result<Vec<(ToolchainDesc, Result<UpdateStatus>)>> {
let channels = self.list_channels()?;
let channels = channels.into_iter();
let profile = self.get_profile()?;

// Update toolchains and collect the results
let channels = tokio_stream::iter(channels).then(|(desc, mut distributable)| async move {
let st = distributable
.update_extra(&[], &[], profile, force_update, false)
.await;
if let Err(e) = &st {
error!("{e}");
}
(desc, st)
});

Ok(channels.collect().await)
}

pub(crate) fn set_default_host_triple(&self, host_triple: String) -> Result<()> {
// Ensure that the provided host_triple is capable of resolving
// against the 'stable' toolchain. This provides early errors
Expand Down Expand Up @@ -944,7 +926,7 @@ impl<'a> Cfg<'a> {

/// The root path of the release server, without the `/dist` suffix.
/// By default, it points to [`dist::DEFAULT_DIST_SERVER`].
pub(crate) fn dist_root_server(process: &Process) -> Result<String> {
fn dist_root_server(process: &Process) -> Result<String> {
if let Some(s) = process.var_opt("RUSTUP_DIST_SERVER")? {
trace!("`RUSTUP_DIST_SERVER` has been set to `{s}`");
return Ok(s);
Expand Down
4 changes: 2 additions & 2 deletions src/dist/manifestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ impl Manifestation {
pub(crate) async fn update_v1(
&self,
new_manifest: &[String],
update_hash: Option<&Path>,
update_hash: &Path,
dl_cfg: &DownloadCfg<'_>,
) -> Result<Option<String>> {
// If there's already a v2 installation then something has gone wrong
Expand All @@ -387,7 +387,7 @@ impl Manifestation {

let status = dl_cfg.status_for("rust");
let dl = dl_cfg
.download_and_check(&url, update_hash, Some(&status), ".tar.gz")
.download_and_check(&url, Some(update_hash), Some(&status), ".tar.gz")
.await?;
if dl.is_none() {
return Ok(None);
Expand Down
Loading