From eff744ebfbad898a66fed6168a4fcbaa56353739 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 10 Dec 2019 19:08:48 +0100 Subject: [PATCH] Add message in case it's already up-to-date --- src/cli/rustup_mode.rs | 2 +- src/cli/self_update.rs | 35 ++++++++++++++++++++--------------- src/errors.rs | 4 ++++ tests/cli-self-upd.rs | 1 + 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index ea579d1eaac..a2c3a4161d4 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -98,7 +98,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 bb077645966..0d78c4ae922 100644 --- a/src/cli/self_update.rs +++ b/src/cli/self_update.rs @@ -34,6 +34,7 @@ use crate::common::{self, Confirm}; use crate::errors::*; use crate::markdown::md; use crate::term2; +use rustup::{Cfg, UpdateStatus}; use rustup::dist::dist::{self, Profile, TargetTriple}; use rustup::utils::utils; use rustup::utils::Notification; @@ -1414,7 +1415,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 @@ -1435,21 +1436,25 @@ 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() { + Ok(Some(ref 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)?; + } + Ok(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()? + } + Err(e) => common::show_channel_update(cfg, "rustup", Err(rustup::ErrorKind::Generic(e.to_string()).into()))?, } Ok(()) diff --git a/src/errors.rs b/src/errors.rs index 7d9a073b4c1..89283329cb8 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -362,6 +362,10 @@ error_chain! { BrokenPartialFile { description("partially downloaded file may have been damaged and was removed, please try again") } + Generic(v: String) { + description("generic error") + display("encountered error: {}", v) + } } } diff --git a/tests/cli-self-upd.rs b/tests/cli-self-upd.rs index 10f4079d8e9..2a6175ffcd4 100644 --- a/tests/cli-self-upd.rs +++ b/tests/cli-self-upd.rs @@ -699,6 +699,7 @@ fn update_no_change() { &["rustup", "self", "update"], r"", r"info: checking for self-updates +info: already up-to-date ", ); });