diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index 8f439223cb..aba1ecb2b6 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -110,7 +110,7 @@ pub fn main() -> Result<()> { ("doc", Some(m)) => doc(cfg, m)?, ("man", Some(m)) => man(cfg, m)?, ("self", Some(c)) => match c.subcommand() { - ("update", Some(_)) => self_update::update()?, + ("update", Some(_)) => self_update::update(cfg)?, ("uninstall", Some(m)) => self_uninstall(m)?, (_, _) => unreachable!(), }, diff --git a/src/cli/self_update.rs b/src/cli/self_update.rs index 609cfdbd8a..2895647a14 100644 --- a/src/cli/self_update.rs +++ b/src/cli/self_update.rs @@ -37,6 +37,7 @@ use crate::term2; use rustup::dist::dist::{self, Profile, TargetTriple}; use rustup::utils::utils; use rustup::utils::Notification; +use rustup::{Cfg, UpdateStatus}; use rustup::{DUP_TOOLS, TOOLS}; use same_file::Handle; use std::env; @@ -1379,7 +1380,7 @@ fn do_remove_from_path(methods: &[PathUpdateMethod]) -> Result<()> { /// (and on windows this process will not be running to do it), /// rustup-init is stored in `CARGO_HOME`/bin, and then deleted next /// time rustup runs. -pub fn update() -> Result<()> { +pub fn update(cfg: &Cfg) -> Result<()> { use common::SelfUpdatePermission::*; let update_permitted = if NEVER_SELF_UPDATE { HardFail @@ -1400,21 +1401,24 @@ pub fn update() -> Result<()> { Permit => {} } - let setup_path = prepare_update()?; - if let Some(ref p) = setup_path { - let version = match get_new_rustup_version(p) { - Some(new_version) => parse_new_rustup_version(new_version), - None => { - err!("failed to get rustup version"); - process::exit(1); - } - }; + match prepare_update()? { + Some(setup_path) => { + let version = match get_new_rustup_version(&setup_path) { + Some(new_version) => parse_new_rustup_version(new_version), + None => { + err!("failed to get rustup version"); + process::exit(1); + } + }; - info!("rustup updated successfully to {}", version); - run_update(p)?; - } else { - // Try again in case we emitted "tool `{}` is already installed" last time. - install_proxies()? + let _ = common::show_channel_update(cfg, "rustup", Ok(UpdateStatus::Updated(version))); + run_update(&setup_path)?; + } + None => { + let _ = common::show_channel_update(cfg, "rustup", Ok(UpdateStatus::Unchanged)); + // Try again in case we emitted "tool `{}` is already installed" last time. + install_proxies()? + } } Ok(()) diff --git a/tests/cli-self-upd.rs b/tests/cli-self-upd.rs index 690ace417c..7dcb0ec17a 100644 --- a/tests/cli-self-upd.rs +++ b/tests/cli-self-upd.rs @@ -568,13 +568,20 @@ fn update_exact() { let expected_output = format!( "info: checking for self-updates info: downloading self-update -info: rustup updated successfully to {}\n", - version +" ); update_setup(&|config, _| { expect_ok(config, &["rustup-init", "-y"]); - expect_ok_ex(config, &["rustup", "self", "update"], r"", &expected_output) + expect_ok_ex( + config, + &["rustup", "self", "update"], + &format!( + " rustup updated - (toolchain not installed) (from {})\n\n", + version, + ), + &expected_output, + ) }); } @@ -696,7 +703,9 @@ fn update_no_change() { expect_ok_ex( config, &["rustup", "self", "update"], - r"", + r" rustup unchanged - (toolchain not installed) + +", r"info: checking for self-updates ", );