uninstalling removes cachedir and smartened errs
parent
2647731d39
commit
1e2d9c785c
@ -1,25 +1,46 @@
|
|||||||
use runas::Command;
|
use runas::Command;
|
||||||
use crate::mods::strs::{err_unrec, sec, succ};
|
use crate::mods::strs::{err_unrec, sec, succ, err_rec};
|
||||||
|
use std::{fs, path::Path};
|
||||||
|
|
||||||
pub fn uninstall(noconfirm: bool, pkg: Vec<String>) {
|
pub fn uninstall(noconfirm: bool, pkgs: Vec<String>) {
|
||||||
sec(format!("Attempting to uninstall packages: {}", &pkg.join(" ")));
|
sec(format!("Attempting to uninstall packages: {}", &pkgs.join(" ")));
|
||||||
if noconfirm == true {
|
if noconfirm == true {
|
||||||
let result = Command::new("pacman").arg("-Rs").args(&pkg).arg("--noconfirm").status();
|
let result = Command::new("pacman").arg("-Rs").args(&pkgs).arg("--noconfirm").status().expect("Couldn't call pacman");
|
||||||
match result {
|
match result.code() {
|
||||||
Ok(_) => {
|
Some(0) => {
|
||||||
succ(format!("Succesfully uninstalled packages: {}", &pkg.join(" ")))
|
succ(format!("Succesfully uninstalled packages: {}", &pkgs.join(" ")))
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Some(_) => {
|
||||||
err_unrec(format!("Couldn't uninstall packages: {}", &pkg.join(" ")))
|
err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" ")))
|
||||||
|
}
|
||||||
|
None =>{
|
||||||
|
err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" ")))
|
||||||
}};
|
}};
|
||||||
} else {
|
} else {
|
||||||
let result = Command::new("pacman").arg("-Rs").args(&pkg).status();
|
let result = Command::new("pacman").arg("-Rs").args(&pkgs).status().expect("Couldn't call pacman");
|
||||||
match result {
|
match result.code() {
|
||||||
Ok(_) => {
|
Some(0) => {
|
||||||
succ(format!("Succesfully uninstalled packages: {}", &pkg.join(" ")))
|
succ(format!("Succesfully uninstalled packages: {}", &pkgs.join(" ")))
|
||||||
|
}
|
||||||
|
Some(_) => {
|
||||||
|
err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" ")))
|
||||||
}
|
}
|
||||||
Err(_) => {
|
None =>{
|
||||||
err_unrec(format!("Couldn't uninstall packages: {}", &pkg.join(" ")))
|
err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" ")))
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
for pkg in &pkgs {
|
||||||
|
let pkgdir = format!("{}/.cache/ame/{}", std::env::var("HOME").unwrap(), pkg);
|
||||||
|
let path = Path::new(&pkgdir);
|
||||||
|
if path.is_dir() {
|
||||||
|
let rm_result = fs::remove_dir_all(&path);
|
||||||
|
match rm_result {
|
||||||
|
Ok(_) => {
|
||||||
|
succ(format!("Removed AUR cache directory for {}", pkg))
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
err_unrec(format!("Failed to remove AUR cache directory for {}", pkg))
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue