Skip to content
Merged
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
13 changes: 7 additions & 6 deletions src/cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,23 +233,24 @@ pub(crate) async fn update_all_channels(
check: bool,
) -> anyhow::Result<ExitCode> {
let profile = cfg.get_profile()?;
let channels = cfg.list_channels()?;
let channels = cfg.list_tracking_channels()?;

// Run a pre-check to determine which channels have updates available.
let channels_with_manifests = join_all(channels.into_iter().map(|(desc, d)| async move {
let channels_with_manifests = join_all(channels.into_iter().map(|d| async move {
// Prefetch errors are intentionally discarded; a failed prefetch falls
// back to the normal update path, where errors are properly propagated.
let manifest = d.fetch_dist_manifest().await.unwrap_or(None);
(desc, d, manifest)
(d, manifest)
}))
.await;

let mut toolchains = Vec::with_capacity(channels_with_manifests.len());
let mut has_update_error = false;
let mut has_update = false;
for (desc, distributable, manifest) in channels_with_manifests {
for (distributable, manifest) in channels_with_manifests {
let desc = distributable.desc();
let result = if force_update || manifest.is_some() {
let options = DistOptions::new(&[], &[], &desc, profile, force_update, cfg)?
let options = DistOptions::new(&[], &[], desc, profile, force_update, cfg)?
.for_update(&distributable, false);
InstallMethod::Dist(options).install(manifest).await
} else {
Expand All @@ -265,7 +266,7 @@ pub(crate) async fn update_all_channels(
_ => (),
}

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

let exit_code = if has_update_error {
Expand Down
6 changes: 3 additions & 3 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ async fn check_updates(cfg: &Cfg<'_>, opts: CheckOpts) -> anyhow::Result<ExitCod
let t = cfg.process.stdout();
let use_colors = matches!(t.color_choice(), ColorChoice::Auto | ColorChoice::Always);
let mut update_available = false;
let channels = cfg.list_channels()?;
let channels = cfg.list_tracking_channels()?;
let channels_len = channels.len();

// Check updates for all channels unless `RUSTUP_CONCURRENT_DOWNLOADS` is set to 1,
Expand All @@ -975,8 +975,8 @@ async fn check_updates(cfg: &Cfg<'_>, opts: CheckOpts) -> anyhow::Result<ExitCod
// Help avoid flickering by moving the cursor instead of clearing the line.
multi_progress_bars.set_move_cursor(true);
let semaphore = Arc::new(Semaphore::new(concurrent_downloads));
let channels = tokio_stream::iter(channels).map(|(name, distributable)| {
let msg = format!("{bold}{name} - {bold:#}");
let channels = tokio_stream::iter(channels).map(|distributable| {
let msg = format!("{bold}{} - {bold:#}", distributable.desc());
let status = "Checking...";
let template = format!(
"{{msg}}{transient}{status}{transient:#} {transient}{{spinner}}{transient:#}"
Expand Down
8 changes: 3 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1033,23 +1033,21 @@ impl<'a> Cfg<'a> {
Ok(toolchains)
}

pub(crate) fn list_channels(
&self,
) -> anyhow::Result<Vec<(ChannelToolchainName, ChannelToolchain<'_>)>> {
pub(crate) fn list_tracking_channels(&self) -> anyhow::Result<Vec<ChannelToolchain<'_>>> {
let mut channels = self
.list_toolchains(true)?
.into_iter()
.filter_map(|t| match t {
ToolchainName::Channel(n) if n.is_tracking() => {
Some(ChannelToolchain::new(self, n.clone()).map(|t| (n, t)))
Some(ChannelToolchain::new(self, n))
}
_ => None,
})
.collect::<Result<Vec<_>, _>>()?;

// HACK: `.sort_by_key()` is impossible here without cloning.
// See: <https://users.rust-lang.org/t/cannot-call-vec-sort-by-key-without-cloning-data/60455/4>
channels.sort_by(|(n, _), (m, _)| n.cmp(m));
channels.sort_by(|n, m| n.desc().cmp(m.desc()));
Ok(channels)
}

Expand Down
Loading