Skip to content

Commit 1d015e1

Browse files
committed
fix(rustup-mode): return ExitCode(1) when update() fails
1 parent 5e31280 commit 1d015e1

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/cli/common.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ pub(crate) async fn update_all_channels(
293293
force_update: bool,
294294
) -> Result<utils::ExitCode> {
295295
let toolchains = cfg.update_all_channels(force_update).await?;
296+
let has_update_error = toolchains.iter().any(|(_, r)| r.is_err());
297+
let mut exit_code = utils::ExitCode(if has_update_error { 1 } else { 0 });
296298

297299
if toolchains.is_empty() {
298300
info!("no updatable toolchains installed");
@@ -312,11 +314,14 @@ pub(crate) async fn update_all_channels(
312314
};
313315

314316
if do_self_update {
315-
self_update(show_channel_updates, cfg.process).await
317+
let self_update_exit_code = self_update(show_channel_updates, cfg.process).await?;
318+
if self_update_exit_code != utils::ExitCode(0) {
319+
exit_code = self_update_exit_code;
320+
}
316321
} else {
317322
show_channel_updates()?;
318-
Ok(utils::ExitCode(0))
319323
}
324+
Ok(exit_code)
320325
}
321326

322327
#[derive(Clone, Copy, Debug)]

src/cli/rustup_mode.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,8 @@ async fn check_updates(cfg: &Cfg<'_>) -> Result<utils::ExitCode> {
789789
}
790790

791791
async fn update(cfg: &mut Cfg<'_>, opts: UpdateOpts) -> Result<utils::ExitCode> {
792+
let mut exit_code = utils::ExitCode(0);
793+
792794
common::warn_if_host_is_emulated(cfg.process);
793795
let self_update_mode = cfg.get_self_update_mode()?;
794796
// Priority: no-self-update feature > self_update_mode > no-self-update args.
@@ -865,7 +867,7 @@ async fn update(cfg: &mut Cfg<'_>, opts: UpdateOpts) -> Result<utils::ExitCode>
865867
common::self_update(|| Ok(()), cfg.process).await?;
866868
}
867869
} else {
868-
common::update_all_channels(cfg, self_update, opts.force).await?;
870+
exit_code = common::update_all_channels(cfg, self_update, opts.force).await?;
869871
info!("cleaning up downloads & tmp directories");
870872
utils::delete_dir_contents_following_links(&cfg.download_dir);
871873
cfg.tmp_cx.clean();
@@ -880,7 +882,7 @@ async fn update(cfg: &mut Cfg<'_>, opts: UpdateOpts) -> Result<utils::ExitCode>
880882
info!("any updates to rustup will need to be fetched with your system package manager")
881883
}
882884

883-
Ok(utils::ExitCode(0))
885+
Ok(exit_code)
884886
}
885887

886888
async fn run(

src/utils/utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub(crate) use crate::utils::utils::raw::is_directory;
2121

2222
pub use crate::utils::utils::raw::{is_file, path_exists};
2323

24+
#[derive(Debug, PartialEq, Eq)]
2425
pub struct ExitCode(pub i32);
2526

2627
impl From<ExitStatus> for ExitCode {

0 commit comments

Comments
 (0)