fix(rustup): remove standalone components

This patch targets the removal of standalone components that are not
removed as a part of a toolchain. This was previously ignored.

Signed-off-by: innocentzero <isfarulhaque@proton.me>
This commit is contained in:
innocentzero
2024-04-02 04:51:15 +05:30
parent 97b4077b02
commit 4e2ef50df7
2 changed files with 32 additions and 10 deletions
+26 -10
View File
@@ -77,8 +77,7 @@ impl Backend for Rustup {
let mut iter = p.name.split('/');
let toolchain = iter.next().expect("Toolchain not specified!");
let component = iter.next().expect("Component not specified!");
cmd.arg(format!("{toolchain}"));
cmd.arg(format!("{component}"));
cmd.arg(format!("{toolchain}")).arg(format!("{component}"));
}
_ => panic!("No such type is managed by rustup!"),
}
@@ -97,15 +96,33 @@ impl Backend for Rustup {
) -> anyhow::Result<std::process::ExitStatus> {
let mut result: anyhow::Result<std::process::ExitStatus> =
Ok(std::process::ExitStatus::from_raw(0));
let mut toolchains_rem = Vec::new();
for p in packages {
let repo = p
.repo
.as_ref()
.expect("Not specified whether it is a toolchain or a component!");
let repo = p.repo("Not specified whether it is a toolchain or a component");
if repo == "toolchain" {
let mut cmd = Command::new(self.get_binary());
cmd.args(self.get_remove_switches(repo));
cmd.arg(format!("{}", p.name));
cmd.args(self.get_remove_switches(repo))
.arg(format!("{}", p.name));
toolchains_rem.push(p.name.as_str());
result = cmd.status().context("Removing toolchain {p}");
if !result.as_ref().is_ok_and(|exit| exit.success()) {
return result;
}
}
}
for p in packages {
let repo = p.repo("Not specified whether it is a toolchain or a component");
let mut iter = p.name.split('/');
let toolchain = iter
.next()
.expect("No toolchain name provided for component");
if repo == "component" && !toolchains_rem.contains(&toolchain) {
let mut cmd = Command::new(self.get_binary());
cmd.args(self.get_remove_switches(repo)).arg(toolchain).arg(
iter.next()
.expect(format!("Component name not provided for {}", p.name).as_str()),
);
result = cmd.status().context("Removing toolchain {p}");
if !result.as_ref().is_ok_and(|exit| exit.success()) {
return result;
@@ -155,8 +172,7 @@ impl Rustup {
let mut val = Vec::new();
for toolchain in toolchains {
let mut cmd = Command::new(self.get_binary());
cmd.args(args);
cmd.arg(&toolchain);
cmd.args(args).arg(&toolchain);
let output = String::from_utf8(cmd.output()?.stdout)?;
for i in output.lines() {
let mut it = i.splitn(3, "-");
@@ -48,6 +48,12 @@ impl Package {
}
}
/// Returns the repo name as a reference.
/// Panics if repo name is `None` with a custom error message.
pub(crate) fn repo(&self, msg: &str) -> &str {
self.repo.as_ref().expect(msg)
}
/// Try to parse a string (from a line in a group file) and return a package.
/// From the string, any possible comment is removed and whitespace is trimmed.
/// Returns `None` if there is nothing left after trimming.