Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(),
},
Expand Down
34 changes: 19 additions & 15 deletions src/cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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(())
Expand Down
17 changes: 13 additions & 4 deletions tests/cli-self-upd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
});
}

Expand Down Expand Up @@ -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
",
);
Expand Down