From 6745cd902b43fad7052b118dc0fb0292509d82fc Mon Sep 17 00:00:00 2001 From: Lea Fairbanks Date: Sat, 9 Oct 2021 16:22:27 -0600 Subject: [PATCH 1/2] uninstalls toolchains prior to deleting the rustup home folder --- src/cli/rustup_mode.rs | 6 +++--- src/cli/self_update.rs | 9 ++++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index a8b36567ae..54c6bfdfe5 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -179,7 +179,7 @@ pub fn main() -> Result { ("man", Some(m)) => man(cfg, m)?, ("self", Some(c)) => match c.subcommand() { ("update", Some(_)) => self_update::update(cfg)?, - ("uninstall", Some(m)) => self_uninstall(m)?, + ("uninstall", Some(m)) => self_uninstall(cfg, m)?, (_, _) => unreachable!(), }, ("set", Some(c)) => match c.subcommand() { @@ -1590,10 +1590,10 @@ fn man(cfg: &Cfg, m: &ArgMatches<'_>) -> Result { Ok(utils::ExitCode(0)) } -fn self_uninstall(m: &ArgMatches<'_>) -> Result { +fn self_uninstall(cfg: &Cfg, m: &ArgMatches<'_>) -> Result { let no_prompt = m.is_present("no-prompt"); - self_update::uninstall(no_prompt) + self_update::uninstall(cfg, no_prompt) } fn set_default_host_triple(cfg: &Cfg, m: &ArgMatches<'_>) -> Result { diff --git a/src/cli/self_update.rs b/src/cli/self_update.rs index 267f26c5e0..da29bd49d4 100644 --- a/src/cli/self_update.rs +++ b/src/cli/self_update.rs @@ -903,7 +903,7 @@ fn _install_selection<'a>( }) } -pub(crate) fn uninstall(no_prompt: bool) -> Result { +pub(crate) fn uninstall(cfg: &Cfg, no_prompt: bool) -> Result { if NEVER_SELF_UPDATE { err!("self-uninstall is disabled for this build of rustup"); err!("you should probably use your system package manager to uninstall rustup"); @@ -926,6 +926,13 @@ pub(crate) fn uninstall(no_prompt: bool) -> Result { } } + info!("removing toolchains"); + let toolchains = cfg.list_toolchains()?; + for toolchain in toolchains { + let toolchain = cfg.get_toolchain(&toolchain, false)?; + toolchain.remove()?; + } + info!("removing rustup home"); // Delete RUSTUP_HOME From ba0ca3db04e9b92eac280812270f6a63446ce599 Mon Sep 17 00:00:00 2001 From: Lea Fairbanks Date: Sat, 25 Feb 2023 14:02:46 -0700 Subject: [PATCH 2/2] add a test for uninstalling toolchains --- tests/suite/cli_self_upd.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/suite/cli_self_upd.rs b/tests/suite/cli_self_upd.rs index d20c502c98..13018fd390 100644 --- a/tests/suite/cli_self_upd.rs +++ b/tests/suite/cli_self_upd.rs @@ -153,6 +153,24 @@ fn uninstall_deletes_bins() { }); } +#[test] +fn uninstall_deletes_installed_toolchains() { + setup_installed(&|config| { + let path = config.customdir.join("custom-1"); + let path = path.to_string_lossy(); + config.expect_ok(&["rustup", "toolchain", "link", "custom", &path]); + config.expect_ok_contains( + &["rustup", "self", "uninstall", "-y"], + "", + r" +info: uninstalling toolchain 'custom' +info: toolchain 'custom' uninstalled +", + ); + assert!(!&config.rustupdir.join("toolchains").exists()) + }); +} + #[test] fn uninstall_works_if_some_bins_dont_exist() { setup_empty_installed(&|config| {