Skip to content

Commit b5a8ec9

Browse files
committed
cli: move self update logic out of check_updates()
1 parent 8abc46a commit b5a8ec9

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/cli/rustup_mode.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -894,16 +894,7 @@ async fn check_updates(cfg: &Cfg<'_>, opts: CheckOpts) -> Result<utils::ExitCode
894894
}
895895
}
896896

897-
let self_update_mode = SelfUpdateMode::from_cfg(cfg)?;
898-
// Priority: no-self-update feature > self_update_mode > no-self-update args.
899-
// Check for update only if rustup does **not** have the no-self-update feature,
900-
// and auto-self-update is configured to **enable**
901-
// and has **no** no-self-update parameter.
902-
let self_update = !cfg!(feature = "no-self-update")
903-
&& self_update_mode == SelfUpdateMode::Enable
904-
&& !opts.no_self_update;
905-
906-
if self_update && check_rustup_update(cfg.process).await? {
897+
if check_rustup_update(opts.no_self_update, cfg).await? {
907898
update_available = true;
908899
}
909900

src/cli/self_update.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ pub(crate) async fn self_update(disabled: bool, cfg: &Cfg<'_>) -> Result<utils::
10971097
info!("self-update is disabled for this build of rustup");
10981098
info!("any updates to rustup will need to be fetched with your system package manager")
10991099
} else if self_update_mode == SelfUpdateMode::CheckOnly {
1100-
check_rustup_update(cfg.process).await?;
1100+
check_rustup_update(disabled, cfg).await?;
11011101
return Ok(utils::ExitCode(0));
11021102
} else if disabled {
11031103
info!("self-update is disabled by command line argument");
@@ -1338,13 +1338,22 @@ impl fmt::Display for SchemaVersion {
13381338
}
13391339

13401340
/// Returns whether an update was available
1341-
pub(crate) async fn check_rustup_update(process: &Process) -> anyhow::Result<bool> {
1342-
let mut t = process.stdout().terminal(process);
1341+
pub(crate) async fn check_rustup_update(disabled: bool, cfg: &Cfg<'_>) -> anyhow::Result<bool> {
1342+
// Priority: no-self-update feature > self_update_mode > no-self-update args.
1343+
// Check for update only if rustup does **not** have the no-self-update feature,
1344+
// and auto-self-update is configured to **enable**
1345+
// and has **no** no-self-update parameter.
1346+
let self_update_mode = SelfUpdateMode::from_cfg(cfg)?;
1347+
if cfg!(feature = "no-self-update") || self_update_mode == SelfUpdateMode::Disable || disabled {
1348+
return Ok(false);
1349+
}
1350+
1351+
let mut t = cfg.process.stdout().terminal(&cfg.process);
13431352
// Get current rustup version
13441353
let current_version = env!("CARGO_PKG_VERSION");
13451354

13461355
// Get available rustup version
1347-
let available_version = get_available_rustup_version(process).await?;
1356+
let available_version = get_available_rustup_version(&cfg.process).await?;
13481357

13491358
let _ = t.attr(terminalsource::Attr::Bold);
13501359
write!(t.lock(), "rustup - ")?;

0 commit comments

Comments
 (0)