Add cache cleaning #13

Merged
luke merged 4 commits from development into main 2024-04-30 21:50:31 +00:00
Showing only changes of commit aa1057dbd8 - Show all commits

View File

@ -7,13 +7,14 @@
*/ */
/* /*
pacman_api.rs pacman.rs
This module provides an api to make working with Pacman much easier. This module provides an api to make working with Pacman much easier.
*/ */
use std::{error, fmt, result}; use std::{error, fmt, result};
use std::fmt::Formatter; use std::fmt::Formatter;
use std::path::Path; use std::path::Path;
use std::process::ExitStatus;
use crate::shell_commands; use crate::shell_commands;
@ -64,16 +65,7 @@ pub fn check() -> Result<()> {
pub fn update_all() -> Result<()> { pub fn update_all() -> Result<()> {
let exit_status = shell_commands::execute_in_sh("sudo pacman -Syu")?; let exit_status = shell_commands::execute_in_sh("sudo pacman -Syu")?;
if !exit_status.success() { check_exit_code(exit_status)
let exit_code = match exit_status.code() {
Some(exit_code) => exit_code,
None => return Err(PacmanError::Other("No Exit Code Found").into()),
};
return Err(PacmanError::ExitCode(exit_code).into());
}
Ok(())
} }
pub fn get_unused() -> Result<Vec<String>> { pub fn get_unused() -> Result<Vec<String>> {
@ -90,9 +82,20 @@ pub fn remove_unused(packages: Vec<String>) -> Result<()> {
let package_string = packages.join(" "); let package_string = packages.join(" ");
let command = format!("sudo pacman -Rns {}", package_string); let command = format!("sudo pacman -Rns {}", package_string);
let out = shell_commands::execute_in_sh(command)?; let exit_status = shell_commands::execute_in_sh(command)?;
dbg!(&out); check_exit_code(exit_status)
}
fn check_exit_code(exit_status: ExitStatus) -> Result<()> {
if !exit_status.success() {
let exit_code = match exit_status.code() {
Some(exit_code) => exit_code,
None => return Err(PacmanError::Other("No Exit Code Found").into()),
};
return Err(PacmanError::ExitCode(exit_code).into());
}
Ok(()) Ok(())
} }