From ab5e337012b63c307efa2f81824d36d95b85d3a4 Mon Sep 17 00:00:00 2001 From: Michal Date: Mon, 4 Jul 2022 14:35:19 +0000 Subject: [PATCH] Amethyst now checks for .pacnew and .pacsave files and prompts the user to run pacdiff if necessary --- src/internal/commands.rs | 4 ++++ src/internal/detect.rs | 29 +++++++++++++++++++++++------ src/internal/mod.rs | 2 ++ src/main.rs | 3 +++ 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/internal/commands.rs b/src/internal/commands.rs index 6020912..09cba04 100644 --- a/src/internal/commands.rs +++ b/src/internal/commands.rs @@ -28,6 +28,10 @@ impl ShellCommand { } } + pub fn pacdiff() -> Self { + Self::new("pacdiff") + } + pub fn makepkg() -> Self { Self::new("makepkg") } diff --git a/src/internal/detect.rs b/src/internal/detect.rs index 28166c2..189c03f 100644 --- a/src/internal/detect.rs +++ b/src/internal/detect.rs @@ -1,9 +1,26 @@ -use crate::internal::strings::info; +use crate::internal::strings::prompt; +use crate::internal::error::SilentUnwrap; +use crate::internal::exit_code::AppExitCode; +use crate::internal::commands::ShellCommand; -pub fn detect(a: String) { - if a.contains(".pacnew") || a.contains(".new") { - info("It appears that a program you have installed / upgraded has installed a .new/.pacnew config file. Please read over the pacman output and act on it accordingly".to_string()); - } else if a.contains(".old") { - info("It appears that a program you have installed / upgraded has installed a .old config file. Please read over the pacman output and act on it accordingly".to_string()); +pub fn detect() { + let mut pacnew = vec![]; + + for entry in std::fs::read_dir("/etc").unwrap() { + let entry = entry.unwrap(); + let path = entry.path(); + if path.to_str().unwrap().contains(".pacnew") || path.to_str().unwrap().contains(".pacsave") { + pacnew.push(path); + } + } + + if !pacnew.is_empty() { + let choice = prompt("It appears that at least one program you have installed / upgraded has installed a .pacnew/.pacsave config file. Would you like to run pacdiff to deal with this?".to_string(), true); + if choice { + ShellCommand::pacdiff() + .elevated() + .wait() + .silent_unwrap(AppExitCode::PacmanError); + } } } diff --git a/src/internal/mod.rs b/src/internal/mod.rs index 5f8be49..7f491d9 100644 --- a/src/internal/mod.rs +++ b/src/internal/mod.rs @@ -7,12 +7,14 @@ pub mod rpc; mod sort; mod strings; pub mod structs; +mod detect; pub use clean::*; pub use initialise::*; pub use sort::*; use std::env; pub use strings::*; +pub use detect::*; #[macro_export] macro_rules! uwu { diff --git a/src/main.rs b/src/main.rs index b3eabae..6002edf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,7 @@ use internal::error::SilentUnwrap; use crate::internal::exit_code::AppExitCode; #[allow(unused_imports)] use crate::internal::{crash, info, init, log, prompt, sort, structs::Options, warn}; +use crate::internal::detect; #[global_allocator] static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; @@ -49,6 +50,8 @@ fn main() { operations::clean(options); } } + + detect(); } fn cmd_install(args: InstallArgs, options: Options) {