Skip to content

Commit 38943b9

Browse files
FranciscoTGouveiarami3l
authored andcommitted
feat(toolchain): run a pre-check before updating all toolchains
1 parent 6576758 commit 38943b9

4 files changed

Lines changed: 23 additions & 12 deletions

File tree

src/cli/common.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ 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};
@@ -213,11 +214,26 @@ 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 channels_with_manifests = join_all(channels.into_iter().map(|(desc, d)| async move {
221+
// Prefetch errors are intentionally discarded; a failed prefetch falls
222+
// back to the normal update path, where errors are properly propagated.
223+
let manifest = d.fetch_dist_manifest().await.unwrap_or(None);
224+
(desc, d, manifest)
225+
}))
226+
.await;
227+
216228
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(None).await;
229+
for (desc, distributable, manifest) in channels_with_manifests {
230+
let result = if force_update || manifest.is_some() {
231+
let options = DistOptions::new(&[], &[], &desc, profile, force_update, cfg)?
232+
.for_update(&distributable, false);
233+
InstallMethod::Dist(options).install(manifest).await
234+
} else {
235+
Ok(UpdateStatus::Unchanged)
236+
};
221237

222238
if let Err(e) = &result {
223239
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)