now also can remove and purge packages specified from a file

i18n
Amy 3 years ago
parent c23bdd5bb9
commit 290b8f1569
No known key found for this signature in database
GPG Key ID: 6672E6DD65BEA50B

@ -1,5 +1,5 @@
mod mods;
use mods::{clearcache::{clearcache}, clone::clone, help::help, inssort::{inssort, inssort_from_file}, install::install, purge::{purge}, search::{a_search, r_search}, strs::err_rec, strs::err_unrec, strs::inf, uninstall::{uninstall}, update::{update}, upgrade::{upgrade}, ver::ver, xargs::*};
use mods::{clearcache::{clearcache}, clone::clone, help::help, inssort::{inssort, inssort_from_file}, install::install, purge::{purge, purge_from_file}, search::{a_search, r_search}, strs::err_rec, strs::err_unrec, strs::inf, uninstall::{uninstall, uninstall_from_file}, update::{update}, upgrade::{upgrade}, ver::ver, xargs::*};
use std::{env, process::exit, process::Command};
use nix::unistd::Uid;
@ -35,6 +35,12 @@ fn main() {
"-Rs" | "-Rsn" | "purge" => {
purge(noconfirm, pkgs)
}
"-Rl" | "-Rln" | "rml" => {
uninstall_from_file(noconfirm, &pkgs[0]);
}
"-Rsl" | "-Rsln" | "purgel" => {
purge_from_file(noconfirm, &pkgs[0]);
}
"-Syu" | "-Syun" |"upg" => {
upgrade(noconfirm);
}

@ -96,7 +96,6 @@ pub fn inssort_from_file(noconfirm: bool, as_dep: bool, file: &str) {
let mut contents = String::new();
contents = std::fs::read_to_string(&file).expect("Couldn't read file");
for line in contents.lines() {
println!("{}", line);
pkgs.push(line.to_string());
}
let mut repo = vec![];

@ -58,3 +58,64 @@ pub fn purge(noconfirm: bool, pkgs: Vec<String>) {
}
}
}
pub fn purge_from_file(noconfirm: bool, file: &str) {
let mut pkgs: Vec<String> = Vec::new();
let mut contents = String::new();
contents = std::fs::read_to_string(&file).expect("Couldn't read file");
for line in contents.lines() {
pkgs.push(line.to_string());
}
sec(format!(
"Attempting to uninstall packages: {}",
&pkgs.join(" ")
));
if noconfirm == true {
let result = Command::new("pacman")
.arg("-Rsu")
.args(&pkgs)
.arg("--noconfirm")
.status()
.expect("Couldn't call pacman");
match result.code() {
Some(0) => {
succ(format!(
"Succesfully uninstalled packages: {}",
&pkgs.join(" ")
));
rem_pkg(&pkgs);
}
Some(_) => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
None => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
};
} else {
let result = Command::new("pacman")
.arg("-Rsu")
.args(&pkgs)
.status()
.expect("Couldn't call pacman");
match result.code() {
Some(0) => {
succ(format!(
"Succesfully uninstalled packages: {}",
&pkgs.join(" ")
));
rem_pkg(&pkgs);
}
Some(_) => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
None => 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)),
};
}
}
}

@ -58,3 +58,63 @@ pub fn uninstall(noconfirm: bool, pkgs: Vec<String>) {
}
}
}
pub fn uninstall_from_file(noconfirm: bool, file: &str) {
let mut pkgs: Vec<String> = Vec::new();
let mut contents = String::new();
contents = std::fs::read_to_string(&file).expect("Couldn't read file");
for line in contents.lines() {
pkgs.push(line.to_string());
}
sec(format!(
"Attempting to uninstall packages: {}",
&pkgs.join(" ")
));
if noconfirm == true {
let result = Command::new("pacman")
.arg("-Ru")
.args(&pkgs)
.arg("--noconfirm")
.status()
.expect("Couldn't call pacman");
match result.code() {
Some(0) => {
succ(format!(
"Succesfully uninstalled packages: {}",
&pkgs.join(" ")
));
rem_pkg(&pkgs);
}
Some(_) => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
None => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
};
} else {
let result = Command::new("pacman")
.arg("-Ru")
.args(&pkgs)
.status()
.expect("Couldn't call pacman");
match result.code() {
Some(0) => {
succ(format!(
"Succesfully uninstalled packages: {}",
&pkgs.join(" ")
));
rem_pkg(&pkgs);
}
Some(_) => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
None => 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…
Cancel
Save