Add cache cleaning (#13)
All checks were successful
Build on Release / cargo-build (push) Successful in 10s
All checks were successful
Build on Release / cargo-build (push) Successful in 10s
Reviewed-on: #13 Increment Version
This commit is contained in:
parent
842dba73ac
commit
ef2134a00b
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -20,7 +20,7 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
|
||||
[[package]]
|
||||
name = "rust-archlinux-update"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
dependencies = [
|
||||
"colored",
|
||||
]
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "rust-archlinux-update"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
edition = "2021"
|
||||
license = "GPL-3"
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
pub mod pacman;
|
10
src/main.rs
10
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());
|
||||
@ -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!");
|
||||
}
|
||||
|
||||
|
14
src/wrappers/mod.rs
Normal file
14
src/wrappers/mod.rs
Normal file
@ -0,0 +1,14 @@
|
||||
/*
|
||||
Rust Arch Linux Updater
|
||||
Copyright (C) 2024 Luke Harding <luke@lukeh990.io>
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
wrappers/mod.rs
|
||||
Just makes pacman accessible
|
||||
*/
|
||||
|
||||
pub mod pacman;
|
@ -7,13 +7,14 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
pacman_api.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};
|
||||
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<Vec<String>> {
|
||||
@ -90,9 +82,26 @@ pub fn remove_unused(packages: Vec<String>) -> 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)
|
||||
}
|
||||
|
||||
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() {
|
||||
Some(exit_code) => exit_code,
|
||||
None => return Err(PacmanError::Other("No Exit Code Found").into()),
|
||||
};
|
||||
|
||||
return Err(PacmanError::ExitCode(exit_code).into());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in New Issue
Block a user