Skip to content

Commit 4968b12

Browse files
Add message in case it's already up-to-date
1 parent 060e84e commit 4968b12

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

src/cli/rustup_mode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub fn main() -> Result<()> {
110110
("doc", Some(m)) => doc(cfg, m)?,
111111
("man", Some(m)) => man(cfg, m)?,
112112
("self", Some(c)) => match c.subcommand() {
113-
("update", Some(_)) => self_update::update()?,
113+
("update", Some(_)) => self_update::update(cfg)?,
114114
("uninstall", Some(m)) => self_uninstall(m)?,
115115
(_, _) => unreachable!(),
116116
},

src/cli/self_update.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use crate::term2;
3737
use rustup::dist::dist::{self, Profile, TargetTriple};
3838
use rustup::utils::utils;
3939
use rustup::utils::Notification;
40+
use rustup::{Cfg, UpdateStatus};
4041
use rustup::{DUP_TOOLS, TOOLS};
4142
use same_file::Handle;
4243
use std::env;
@@ -1379,7 +1380,7 @@ fn do_remove_from_path(methods: &[PathUpdateMethod]) -> Result<()> {
13791380
/// (and on windows this process will not be running to do it),
13801381
/// rustup-init is stored in `CARGO_HOME`/bin, and then deleted next
13811382
/// time rustup runs.
1382-
pub fn update() -> Result<()> {
1383+
pub fn update(cfg: &Cfg) -> Result<()> {
13831384
use common::SelfUpdatePermission::*;
13841385
let update_permitted = if NEVER_SELF_UPDATE {
13851386
HardFail
@@ -1400,21 +1401,24 @@ pub fn update() -> Result<()> {
14001401
Permit => {}
14011402
}
14021403

1403-
let setup_path = prepare_update()?;
1404-
if let Some(ref p) = setup_path {
1405-
let version = match get_new_rustup_version(p) {
1406-
Some(new_version) => parse_new_rustup_version(new_version),
1407-
None => {
1408-
err!("failed to get rustup version");
1409-
process::exit(1);
1410-
}
1411-
};
1404+
match prepare_update()? {
1405+
Some(setup_path) => {
1406+
let version = match get_new_rustup_version(&setup_path) {
1407+
Some(new_version) => parse_new_rustup_version(new_version),
1408+
None => {
1409+
err!("failed to get rustup version");
1410+
process::exit(1);
1411+
}
1412+
};
14121413

1413-
info!("rustup updated successfully to {}", version);
1414-
run_update(p)?;
1415-
} else {
1416-
// Try again in case we emitted "tool `{}` is already installed" last time.
1417-
install_proxies()?
1414+
let _ = common::show_channel_update(cfg, "rustup", Ok(UpdateStatus::Updated(version)));
1415+
run_update(&setup_path)?;
1416+
}
1417+
None => {
1418+
let _ = common::show_channel_update(cfg, "rustup", Ok(UpdateStatus::Unchanged));
1419+
// Try again in case we emitted "tool `{}` is already installed" last time.
1420+
install_proxies()?
1421+
}
14181422
}
14191423

14201424
Ok(())

tests/cli-self-upd.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,15 @@ info: rustup updated successfully to {}\n",
574574

575575
update_setup(&|config, _| {
576576
expect_ok(config, &["rustup-init", "-y"]);
577-
expect_ok_ex(config, &["rustup", "self", "update"], r"", &expected_output)
577+
expect_ok_ex(
578+
config,
579+
&["rustup", "self", "update"],
580+
&format!(
581+
" rustup updated - (toolchain not installed) (from {})\n\n",
582+
version,
583+
),
584+
&expected_output,
585+
)
578586
});
579587
}
580588

@@ -698,6 +706,7 @@ fn update_no_change() {
698706
&["rustup", "self", "update"],
699707
r"",
700708
r"info: checking for self-updates
709+
info: already up-to-date
701710
",
702711
);
703712
});

0 commit comments

Comments
 (0)