Skip to content

Commit 870f3a5

Browse files
authored
Merge pull request #2152 from GuillaumeGomez/up-to-date-msg
Add message in case it's already up-to-date
2 parents 060e84e + bb4073e commit 870f3a5

File tree

3 files changed

+33
-20
lines changed

3 files changed

+33
-20
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: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -568,13 +568,20 @@ fn update_exact() {
568568
let expected_output = format!(
569569
"info: checking for self-updates
570570
info: downloading self-update
571-
info: rustup updated successfully to {}\n",
572-
version
571+
"
573572
);
574573

575574
update_setup(&|config, _| {
576575
expect_ok(config, &["rustup-init", "-y"]);
577-
expect_ok_ex(config, &["rustup", "self", "update"], r"", &expected_output)
576+
expect_ok_ex(
577+
config,
578+
&["rustup", "self", "update"],
579+
&format!(
580+
" rustup updated - (toolchain not installed) (from {})\n\n",
581+
version,
582+
),
583+
&expected_output,
584+
)
578585
});
579586
}
580587

@@ -696,7 +703,9 @@ fn update_no_change() {
696703
expect_ok_ex(
697704
config,
698705
&["rustup", "self", "update"],
699-
r"",
706+
r" rustup unchanged - (toolchain not installed)
707+
708+
",
700709
r"info: checking for self-updates
701710
",
702711
);

0 commit comments

Comments
 (0)