From aa1057dbd82883f48f8a1999ccc6fc7ef0fb5203 Mon Sep 17 00:00:00 2001 From: Luke Harding Date: Tue, 30 Apr 2024 17:22:56 -0400 Subject: [PATCH 1/4] New check_exit_code fn The new check_exit_code fn in pacman.rs allows update_all and remove_unused to share the logic that checks exit codes and returns an error if not 0. --- src/apis/pacman.rs | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/apis/pacman.rs b/src/apis/pacman.rs index 0f7f4a0..8b562fb 100644 --- a/src/apis/pacman.rs +++ b/src/apis/pacman.rs @@ -7,13 +7,14 @@ */ /* - pacman_api.rs + pacman.rs This module provides an api to make working with Pacman much easier. */ use std::{error, fmt, result}; use std::fmt::Formatter; use std::path::Path; +use std::process::ExitStatus; use crate::shell_commands; @@ -64,16 +65,7 @@ pub fn check() -> Result<()> { pub fn update_all() -> Result<()> { let exit_status = shell_commands::execute_in_sh("sudo pacman -Syu")?; - 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(()) + check_exit_code(exit_status) } pub fn get_unused() -> Result> { @@ -90,9 +82,20 @@ pub fn remove_unused(packages: Vec) -> Result<()> { let package_string = packages.join(" "); 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(()) } -- 2.45.2 From 9d264ecbf49648f6ac9734c466eb8b6022c5bdba Mon Sep 17 00:00:00 2001 From: Luke Harding Date: Tue, 30 Apr 2024 17:39:48 -0400 Subject: [PATCH 2/4] Add cache clearing --- src/apis/pacman.rs | 6 ++++++ src/main.rs | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/apis/pacman.rs b/src/apis/pacman.rs index 8b562fb..a408c13 100644 --- a/src/apis/pacman.rs +++ b/src/apis/pacman.rs @@ -87,6 +87,12 @@ pub fn remove_unused(packages: Vec) -> Result<()> { check_exit_code(exit_status) } +pub fn clean_cache() -> Result<()> { + let exit_status = shell_commands::execute_in_sh("sudo pacman -Scc")?; + + check_exit_code(exit_status) +} + fn check_exit_code(exit_status: ExitStatus) -> Result<()> { if !exit_status.success() { let exit_code = match exit_status.code() { diff --git a/src/main.rs b/src/main.rs index fe7dec9..ffb4106 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,6 +50,12 @@ fn main() { return; } + notice_println("Clearing Cache"); + if let Err(e) = pacman::clean_cache() { + error_println(e.to_string()); + return; + } + notice_println("\nUpdate process complete!"); } -- 2.45.2 From 41a7eb90c55184fbad38406fbb7e63366a02710e Mon Sep 17 00:00:00 2001 From: Luke Harding Date: Tue, 30 Apr 2024 17:42:58 -0400 Subject: [PATCH 3/4] Change api folder to wrappers --- src/main.rs | 4 ++-- src/{apis => wrappers}/mod.rs | 1 + src/{apis => wrappers}/pacman.rs | 0 3 files changed, 3 insertions(+), 2 deletions(-) rename src/{apis => wrappers}/mod.rs (61%) rename src/{apis => wrappers}/pacman.rs (100%) diff --git a/src/main.rs b/src/main.rs index ffb4106..542aa09 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,10 +13,10 @@ use colored::{ColoredString, Colorize}; -use apis::pacman; +use wrappers::pacman; -mod apis; mod shell_commands; +mod wrappers; fn main() { println!("{}", copyright_notice()); diff --git a/src/apis/mod.rs b/src/wrappers/mod.rs similarity index 61% rename from src/apis/mod.rs rename to src/wrappers/mod.rs index f4da7e8..f85cc17 100644 --- a/src/apis/mod.rs +++ b/src/wrappers/mod.rs @@ -1 +1,2 @@ pub mod pacman; +mod paru; diff --git a/src/apis/pacman.rs b/src/wrappers/pacman.rs similarity index 100% rename from src/apis/pacman.rs rename to src/wrappers/pacman.rs -- 2.45.2 From 9c59a838ad7dc6ec46f63a4febbff55c0c6463ee Mon Sep 17 00:00:00 2001 From: Luke Harding Date: Tue, 30 Apr 2024 17:49:15 -0400 Subject: [PATCH 4/4] Update documentation in wrappers/mod and wrappers/pacman --- src/wrappers/mod.rs | 14 +++++++++++++- src/wrappers/pacman.rs | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/wrappers/mod.rs b/src/wrappers/mod.rs index f85cc17..3b08948 100644 --- a/src/wrappers/mod.rs +++ b/src/wrappers/mod.rs @@ -1,2 +1,14 @@ +/* + Rust Arch Linux Updater + Copyright (C) 2024 Luke Harding + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along with this program. If not, see . +*/ + +/* + wrappers/mod.rs + Just makes pacman accessible +*/ + pub mod pacman; -mod paru; diff --git a/src/wrappers/pacman.rs b/src/wrappers/pacman.rs index a408c13..40d42a9 100644 --- a/src/wrappers/pacman.rs +++ b/src/wrappers/pacman.rs @@ -7,8 +7,8 @@ */ /* - pacman.rs - This module provides an api to make working with Pacman much easier. + wrappers/pacman.rs + This module provides a wrapper to make working with Pacman much easier. */ use std::{error, fmt, result}; -- 2.45.2