From 97b4077b02b95c10bb22a60b03f51769bd0fc10c Mon Sep 17 00:00:00 2001 From: innocentzero Date: Wed, 28 Feb 2024 03:45:52 +0530 Subject: [PATCH] feat(rustup): Remove packages Signed-off-by: innocentzero --- .../pacdef_core/src/backend/actual/rustup.rs | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/crates/pacdef_core/src/backend/actual/rustup.rs b/crates/pacdef_core/src/backend/actual/rustup.rs index cc1ecb6..2f63ddd 100644 --- a/crates/pacdef_core/src/backend/actual/rustup.rs +++ b/crates/pacdef_core/src/backend/actual/rustup.rs @@ -90,20 +90,23 @@ impl Backend for Rustup { result } + fn remove_packages( + &self, + packages: &[Package], + _: bool, + ) -> anyhow::Result { + let mut result: anyhow::Result = + Ok(std::process::ExitStatus::from_raw(0)); for p in packages { let repo = p .repo .as_ref() - .expect("Not specified wether it is a component or a toolchain!"); - if repo == "component" { - let mut iter = p.name.split('/'); - let toolchain = iter.next().expect("Toolchain not specified!"); - let component = iter.next().expect("Component not specified!"); + .expect("Not specified whether it is a toolchain or a component!"); + if repo == "toolchain" { let mut cmd = Command::new(self.get_binary()); - cmd.args(&[&"component", &"add"]); - cmd.args([&"--toolchain", format!("{toolchain}").as_str()]); - cmd.arg(format!("{component}")); - result = cmd.status().context("Installing component {p}"); + cmd.args(self.get_remove_switches(repo)); + cmd.arg(format!("{}", p.name)); + result = cmd.status().context("Removing toolchain {p}"); if !result.as_ref().is_ok_and(|exit| exit.success()) { return result; } @@ -128,6 +131,14 @@ impl Rustup { } } + fn get_remove_switches(&self, repotype: &str) -> Switches { + match repotype { + "toolchain" => &["toolchain", "uninstall"], + "component" => &["component", "remove", "--toolchain"], + _ => panic!("No such type managed by rust"), + } + } + fn get_info_switches(&self, repotype: &str) -> Switches { match repotype { "toolchain" => &["toolchain", "list"],