Skip to content

Commit eff744e

Browse files
Add message in case it's already up-to-date
1 parent 1249d1e commit eff744e

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

src/cli/rustup_mode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub fn main() -> Result<()> {
9898
("doc", Some(m)) => doc(cfg, m)?,
9999
("man", Some(m)) => man(cfg, m)?,
100100
("self", Some(c)) => match c.subcommand() {
101-
("update", Some(_)) => self_update::update()?,
101+
("update", Some(_)) => self_update::update(cfg)?,
102102
("uninstall", Some(m)) => self_uninstall(m)?,
103103
(_, _) => unreachable!(),
104104
},

src/cli/self_update.rs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use crate::common::{self, Confirm};
3434
use crate::errors::*;
3535
use crate::markdown::md;
3636
use crate::term2;
37+
use rustup::{Cfg, UpdateStatus};
3738
use rustup::dist::dist::{self, Profile, TargetTriple};
3839
use rustup::utils::utils;
3940
use rustup::utils::Notification;
@@ -1414,7 +1415,7 @@ fn do_remove_from_path(methods: &[PathUpdateMethod]) -> Result<()> {
14141415
/// (and on windows this process will not be running to do it),
14151416
/// rustup-init is stored in `CARGO_HOME`/bin, and then deleted next
14161417
/// time rustup runs.
1417-
pub fn update() -> Result<()> {
1418+
pub fn update(cfg: &Cfg) -> Result<()> {
14181419
use common::SelfUpdatePermission::*;
14191420
let update_permitted = if NEVER_SELF_UPDATE {
14201421
HardFail
@@ -1435,21 +1436,25 @@ pub fn update() -> Result<()> {
14351436
Permit => {}
14361437
}
14371438

1438-
let setup_path = prepare_update()?;
1439-
if let Some(ref p) = setup_path {
1440-
let version = match get_new_rustup_version(p) {
1441-
Some(new_version) => parse_new_rustup_version(new_version),
1442-
None => {
1443-
err!("failed to get rustup version");
1444-
process::exit(1);
1445-
}
1446-
};
1439+
match prepare_update() {
1440+
Ok(Some(ref setup_path)) => {
1441+
let version = match get_new_rustup_version(setup_path) {
1442+
Some(new_version) => parse_new_rustup_version(new_version),
1443+
None => {
1444+
err!("failed to get rustup version");
1445+
process::exit(1);
1446+
}
1447+
};
14471448

1448-
info!("rustup updated successfully to {}", version);
1449-
run_update(p)?;
1450-
} else {
1451-
// Try again in case we emitted "tool `{}` is already installed" last time.
1452-
install_proxies()?
1449+
let _ = common::show_channel_update(cfg, "rustup", Ok(UpdateStatus::Updated(version)));
1450+
run_update(setup_path)?;
1451+
}
1452+
Ok(None) => {
1453+
let _ = common::show_channel_update(cfg, "rustup", Ok(UpdateStatus::Unchanged));
1454+
// Try again in case we emitted "tool `{}` is already installed" last time.
1455+
install_proxies()?
1456+
}
1457+
Err(e) => common::show_channel_update(cfg, "rustup", Err(rustup::ErrorKind::Generic(e.to_string()).into()))?,
14531458
}
14541459

14551460
Ok(())

src/errors.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,10 @@ error_chain! {
362362
BrokenPartialFile {
363363
description("partially downloaded file may have been damaged and was removed, please try again")
364364
}
365+
Generic(v: String) {
366+
description("generic error")
367+
display("encountered error: {}", v)
368+
}
365369
}
366370
}
367371

tests/cli-self-upd.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,7 @@ fn update_no_change() {
699699
&["rustup", "self", "update"],
700700
r"",
701701
r"info: checking for self-updates
702+
info: already up-to-date
702703
",
703704
);
704705
});

0 commit comments

Comments
 (0)