Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uninstalls toolchains prior to deleting the rustup home folder #2864

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ pub fn main() -> Result<utils::ExitCode> {
("self", c) => match c.subcommand() {
Some(s) => match s {
("update", _) => self_update::update(cfg)?,
("uninstall", m) => self_uninstall(m)?,
("uninstall", m) => self_uninstall(cfg, m)?,
_ => unreachable!(),
},
None => unreachable!(),
Expand Down Expand Up @@ -1635,10 +1635,9 @@ fn man(cfg: &Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {
Ok(utils::ExitCode(0))
}

fn self_uninstall(m: &ArgMatches) -> Result<utils::ExitCode> {
let no_prompt = m.get_flag("no-prompt");

self_update::uninstall(no_prompt)
fn self_uninstall(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<utils::ExitCode> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't have a lifetime argument here.

let no_prompt = m.is_present("no-prompt");
self_update::uninstall(cfg, no_prompt)
}

fn set_default_host_triple(cfg: &Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {
Expand Down
9 changes: 8 additions & 1 deletion src/cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ fn _install_selection<'a>(
})
}

pub(crate) fn uninstall(no_prompt: bool) -> Result<utils::ExitCode> {
pub(crate) fn uninstall(cfg: &Cfg, no_prompt: bool) -> Result<utils::ExitCode> {
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");
Expand All @@ -926,6 +926,13 @@ pub(crate) fn uninstall(no_prompt: bool) -> Result<utils::ExitCode> {
}
}

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
Expand Down
18 changes: 18 additions & 0 deletions tests/suite/cli_self_upd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down