Skip to content

Simplify updates #4404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
33 changes: 12 additions & 21 deletions src/cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,24 +291,20 @@ pub(crate) async fn update_all_channels(
info!("no updatable toolchains installed");
}

let show_channel_updates = || {
if !toolchains.is_empty() {
writeln!(cfg.process.stdout().lock())?;

let t = toolchains
.into_iter()
.map(|(p, s)| (PackageUpdate::Toolchain(p), s))
.collect();
show_channel_updates(cfg, t)?;
}
Ok(())
};
if !toolchains.is_empty() {
writeln!(cfg.process.stdout().lock())?;

let t = toolchains
.into_iter()
.map(|(p, s)| (PackageUpdate::Toolchain(p), s))
.collect();
show_channel_updates(cfg, t)?;
Copy link
Member

@rami3l rami3l Jul 9, 2025

Choose a reason for hiding this comment

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

Sorry, but I'm a bit confused about this... Do you know why are we showing channel updates during self update in the first place? That might help with understanding the current behavior...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#1605 mentions

This will make sure people who do rustup update stable still get a new rustup

Copy link
Member

Choose a reason for hiding this comment

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

@djc Thanks for mentioning that PR!

After another it looks like this change is basically inlining the show_channel_updates() calls, and the only difference is that in the original version might do other fallible things before printing the channel updates.

Given that, maybe I have misunderstood your original commit message, which gave me the impression of something related to --no-self-update. How about "Show channel updates even if self update is not permitted", so it's clear that it's related to SelfUpdatePermission?

}

if do_self_update {
exit_code &= self_update(show_channel_updates, cfg.process).await?;
} else {
show_channel_updates()?;
exit_code &= self_update(cfg.process).await?;
}

Ok(exit_code)
}

Expand Down Expand Up @@ -350,10 +346,7 @@ pub(crate) fn self_update_permitted(explicit: bool) -> Result<SelfUpdatePermissi
}

/// Performs all of a self-update: check policy, download, apply and exit.
pub(crate) async fn self_update<F>(before_restart: F, process: &Process) -> Result<utils::ExitCode>
where
F: FnOnce() -> Result<()>,
{
pub(crate) async fn self_update(process: &Process) -> Result<utils::ExitCode> {
match self_update_permitted(false)? {
SelfUpdatePermission::HardFail => {
error!("Unable to self-update. STOP");
Expand All @@ -366,8 +359,6 @@ where

let setup_path = self_update::prepare_update(process).await?;

before_restart()?;

if let Some(setup_path) = &setup_path {
return self_update::run_update(setup_path);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ async fn update(
}
}
if self_update {
exit_code &= common::self_update(|| Ok(()), cfg.process).await?;
exit_code &= common::self_update(cfg.process).await?;
}
} else if ensure_active_toolchain {
let (toolchain, reason) = cfg.ensure_active_toolchain(force_non_host, true).await?;
Expand Down