Skip to content

Commit

Permalink
Add message in case it's already up-to-date
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Jan 8, 2020
1 parent 1249d1e commit eff744e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(),
},
Expand Down
35 changes: 20 additions & 15 deletions src/cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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(())
Expand Down
4 changes: 4 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down
1 change: 1 addition & 0 deletions tests/cli-self-upd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,7 @@ fn update_no_change() {
&["rustup", "self", "update"],
r"",
r"info: checking for self-updates
info: already up-to-date
",
);
});
Expand Down

0 comments on commit eff744e

Please sign in to comment.