Skip to content

Commit 3afbe36

Browse files
feat(toolchain): run a pre-check before updating all toolchains
1 parent 4a68765 commit 3afbe36

4 files changed

Lines changed: 25 additions & 13 deletions

File tree

src/cli/common.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ use std::{cmp, env};
1010
use anstyle::Style;
1111
use anyhow::{Context, Result, anyhow};
1212
use clap_cargo::style::{CONTEXT, ERROR, UPDATE_ADDED, UPDATE_UNCHANGED, UPDATE_UPGRADED};
13+
use futures_util::future::join_all;
1314
use git_testament::{git_testament, render_testament};
1415
use tracing::{error, info, warn};
1516
use tracing_subscriber::{EnvFilter, Registry, reload::Handle};
1617

1718
use crate::{
1819
config::Cfg,
19-
dist::{DistOptions, TargetTriple, ToolchainDesc},
20+
dist::{DistOptions, TargetTriple, ToolchainDesc, manifest::Manifest},
2021
errors::RustupError,
2122
install::{InstallMethod, UpdateStatus},
2223
process::Process,
@@ -213,11 +214,27 @@ fn show_channel_updates(
213214

214215
pub(crate) async fn update_all_channels(cfg: &Cfg<'_>, force_update: bool) -> Result<ExitCode> {
215216
let profile = cfg.get_profile()?;
217+
let channels = cfg.list_channels()?;
218+
219+
// Run a pre-check to determine which channels have updates available.
220+
let prefetched_manifests: Vec<Option<(Manifest, String)>> =
221+
join_all(channels.iter().map(|(_, d)| d.fetch_dist_manifest()))
222+
.await
223+
.into_iter()
224+
.map(|r| r.unwrap_or(None))
225+
.collect();
226+
216227
let mut toolchains = Vec::new();
217-
for (desc, distributable) in cfg.list_channels()? {
218-
let options = DistOptions::new(&[], &[], &desc, profile, force_update, cfg)?
219-
.for_update(&distributable, false);
220-
let result = InstallMethod::Dist(options).install().await;
228+
for ((desc, distributable), manifest) in channels.into_iter().zip(prefetched_manifests) {
229+
let result = if force_update || manifest.is_some() {
230+
let options = DistOptions::new(&[], &[], &desc, profile, force_update, cfg)?
231+
.for_update(&distributable, false);
232+
InstallMethod::Dist(options)
233+
.install_with_manifest(manifest)
234+
.await
235+
} else {
236+
Ok(UpdateStatus::Unchanged)
237+
};
221238

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

tests/suite/cli_rustup.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ async fn rustup_stable_no_change() {
9797
9898
"#]])
9999
.with_stderr(snapbox::str![[r#"
100-
info: syncing channel updates for stable-[HOST_TRIPLE]
101100
info: cleaning up downloads & tmp directories
102101
103102
"#]])
@@ -210,7 +209,6 @@ info: syncing channel updates for stable-[HOST_TRIPLE]
210209
info: latest update on 2015-01-02 for version 1.1.0 (hash-stable-1.1.0)
211210
info: removing previous version of component cargo
212211
...
213-
info: syncing channel updates for beta-[HOST_TRIPLE]
214212
info: syncing channel updates for nightly-[HOST_TRIPLE]
215213
info: latest update on 2015-01-02 for version 1.3.0 (hash-nightly-2)
216214
info: removing previous version of component cargo

tests/suite/cli_rustup_ui/rustup_update_no_change.stderr.term.svg

Lines changed: 3 additions & 5 deletions
Loading

tests/suite/cli_self_upd.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,6 @@ async fn rustup_self_update_exact() {
690690
691691
"#]])
692692
.with_stderr(snapbox::str![[r#"
693-
info: syncing channel updates for stable-[HOST_TRIPLE]
694693
info: checking for self-update (current version: [CURRENT_VERSION])
695694
info: downloading self-update (new version: [TEST_VERSION])
696695
info: cleaning up downloads & tmp directories

0 commit comments

Comments
 (0)