Skip to content

Commit 9f532de

Browse files
committed
self update after updating a single toolchain
1 parent bcc1c2b commit 9f532de

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

src/rustup-cli/common.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,30 +200,41 @@ fn show_channel_updates(
200200
Ok(())
201201
}
202202

203-
pub fn update_all_channels(cfg: &Cfg, self_update: bool, force_update: bool) -> Result<()> {
203+
pub fn update_all_channels(cfg: &Cfg, do_self_update: bool, force_update: bool) -> Result<()> {
204204
let toolchains = cfg.update_all_channels(force_update)?;
205205

206206
if toolchains.is_empty() {
207207
info!("no updatable toolchains installed");
208208
}
209209

210-
let setup_path = if self_update {
211-
self_update::prepare_update()?
212-
} else {
213-
None
214-
};
210+
let show_channel_updates = || {
211+
if !toolchains.is_empty() {
212+
println!("");
215213

216-
if !toolchains.is_empty() {
217-
println!("");
214+
show_channel_updates(cfg, toolchains)?;
215+
}
216+
Ok(())
217+
};
218218

219-
show_channel_updates(cfg, toolchains)?;
219+
if do_self_update {
220+
self_update(show_channel_updates)
221+
} else {
222+
show_channel_updates()
220223
}
224+
}
225+
226+
pub fn self_update<F>(before_restart: F) -> Result<()>
227+
where F: FnOnce() -> Result<()>
228+
{
229+
let setup_path = self_update::prepare_update()?;
230+
231+
before_restart()?;
221232

222233
if let Some(ref setup_path) = setup_path {
223234
self_update::run_update(setup_path)?;
224235

225236
unreachable!(); // update exits on success
226-
} else if self_update {
237+
} else {
227238
// Try again in case we emitted "tool `{}` is already installed" last time.
228239
self_update::install_proxies()?;
229240
}

src/rustup-cli/rustup_mode.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ fn default_(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
577577
}
578578

579579
fn update(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
580+
let self_update = !m.is_present("no-self-update") && !self_update::NEVER_SELF_UPDATE;
580581
if let Some(names) = m.values_of("toolchain") {
581582
for name in names {
582583
update_bare_triple_check(cfg, name)?;
@@ -595,10 +596,13 @@ fn update(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
595596
common::show_channel_update(cfg, toolchain.name(), Ok(status))?;
596597
}
597598
}
599+
if self_update {
600+
common::self_update(|| Ok(()))?;
601+
}
598602
} else {
599603
common::update_all_channels(
600604
cfg,
601-
!m.is_present("no-self-update") && !self_update::NEVER_SELF_UPDATE,
605+
self_update,
602606
m.is_present("force"),
603607
)?;
604608
}

0 commit comments

Comments
 (0)