Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions src/cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::{cmp, env};
use anstyle::Style;
use anyhow::{Context, Result, anyhow};
use clap_cargo::style::{CONTEXT, ERROR, UPDATE_ADDED, UPDATE_UNCHANGED, UPDATE_UPGRADED};
use futures_util::future::join_all;
use git_testament::{git_testament, render_testament};
use tracing::{error, info, warn};
use tracing_subscriber::{EnvFilter, Registry, reload::Handle};
Expand Down Expand Up @@ -213,11 +214,29 @@ fn show_channel_updates(

pub(crate) async fn update_all_channels(cfg: &Cfg<'_>, force_update: bool) -> Result<ExitCode> {
let profile = cfg.get_profile()?;
let channels = cfg.list_channels()?;

// Run a pre-check to determine which channels have updates available.
// This step is skipped when force-updating.
Comment on lines +219 to +220
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feedback on the wording of the comment is welcome :)

let needs_update = if force_update {
vec![true; channels.len()]
} else {
join_all(channels.iter().map(|(_, d)| d.show_dist_version()))
.await
.into_iter()
.map(|v| v.map_or(true, |opt| opt.is_some()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused by this logic. show_dist_version() seems to merely yield the latest available version, but that a DistributableToolchain has a manifest with a rust component with a version is_some() doesn't mean that it's newer than the installed version?

.collect()
};

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;
for ((desc, distributable), needs) in channels.into_iter().zip(needs_update) {
let result = if needs {
let options = DistOptions::new(&[], &[], &desc, profile, force_update, cfg)?
.for_update(&distributable, false);
InstallMethod::Dist(options).install().await
} else {
Ok(UpdateStatus::Unchanged)
};

if let Err(e) = &result {
error!("{e}");
Expand Down
2 changes: 0 additions & 2 deletions tests/suite/cli_rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ async fn rustup_stable_no_change() {

"#]])
.with_stderr(snapbox::str![[r#"
info: syncing channel updates for stable-[HOST_TRIPLE]
info: cleaning up downloads & tmp directories

"#]])
Expand Down Expand Up @@ -210,7 +209,6 @@ info: syncing channel updates for stable-[HOST_TRIPLE]
info: latest update on 2015-01-02 for version 1.1.0 (hash-stable-1.1.0)
info: removing previous version of component cargo
...
info: syncing channel updates for beta-[HOST_TRIPLE]
info: syncing channel updates for nightly-[HOST_TRIPLE]
info: latest update on 2015-01-02 for version 1.3.0 (hash-nightly-2)
info: removing previous version of component cargo
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion tests/suite/cli_self_upd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,6 @@ async fn rustup_self_update_exact() {

"#]])
.with_stderr(snapbox::str![[r#"
info: syncing channel updates for stable-[HOST_TRIPLE]
info: checking for self-update (current version: [CURRENT_VERSION])
info: downloading self-update (new version: [TEST_VERSION])
info: cleaning up downloads & tmp directories
Expand Down
Loading