From 3875f973d1f9462fbd0c50425e438c3c761c5887 Mon Sep 17 00:00:00 2001 From: Roey Darwish Dror Date: Tue, 2 Oct 2018 11:36:10 +0300 Subject: [PATCH] Show pacsave/pacnew files in summary (fix #70) --- Cargo.lock | 21 +++++++++++++++++++++ Cargo.toml | 1 + src/linux.rs | 27 +++++++++++++++++++++++++++ src/main.rs | 10 +++++++++- 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 06477af8..b70ac977 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -222,6 +222,14 @@ name = "rustc-demangle" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "same-file" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "serde" version = "1.0.79" @@ -365,6 +373,7 @@ dependencies = [ "term_size 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "walkdir 2.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "which 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -398,6 +407,16 @@ name = "version_check" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "walkdir" +version = "2.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "same-file 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "which" version = "2.0.0" @@ -481,6 +500,7 @@ dependencies = [ "checksum regex 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "2069749032ea3ec200ca51e4a31df41759190a88edca0d2d86ee8bedf7073341" "checksum regex-syntax 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "747ba3b235651f6e2f67dfa8bcdcd073ddb7c243cb21c442fc12395dfcac212d" "checksum rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "bcfe5b13211b4d78e5c2cadfebd7769197d95c639c35a50057eb4c05de811395" +"checksum same-file 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "10f7794e2fda7f594866840e95f5c5962e886e228e68b6505885811a94dd728c" "checksum serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)" = "84257ccd054dc351472528c8587b4de2dbf0dc0fe2e634030c1a90bfdacebaa9" "checksum serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)" = "31569d901045afbff7a9479f793177fe9259819aff10ab4f89ef69bbc5f567fe" "checksum shellexpand 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de7a5b5a9142fd278a10e0209b021a1b85849352e6951f4f914735c976737564" @@ -502,6 +522,7 @@ dependencies = [ "checksum utf8-ranges 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fd70f467df6810094968e2fce0ee1bd0e87157aceb026a8c083bcf5e25b9efe4" "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" +"checksum walkdir 2.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "af464bc7be7b785c7ac72e266a6b67c4c9070155606f51655a650a6686204e35" "checksum which 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49c4f580e93079b70ac522e7bdebbe1568c8afa7d8d05ee534ee737ca37d2f51" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" diff --git a/Cargo.toml b/Cargo.toml index e6dcef82..0645a636 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,7 @@ log = "0.4.5" env_logger = "0.5.13" term_size = "0.3.1" termcolor = "1.0.4" +walkdir = "2.2.5" [profile.release] lto = true diff --git a/src/linux.rs b/src/linux.rs index 70cb62af..22018b91 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -4,6 +4,7 @@ use super::utils::{which, Check}; use failure; use std::fs; use std::path::PathBuf; +use walkdir::WalkDir; #[derive(Copy, Clone, Debug)] pub enum Distribution { @@ -67,6 +68,32 @@ impl Distribution { Some(("System update", success.is_ok())) } + + pub fn show_summary(self) { + if let Distribution::Arch = self { + show_pacnew(); + } + } +} + +pub fn show_pacnew() { + let mut iter = WalkDir::new("/etc") + .into_iter() + .filter_map(|e| e.ok()) + .filter(|f| { + f.path() + .extension() + .filter(|ext| ext == &"pacnew" || ext == &"pacsave") + .is_some() + }).peekable(); + + if iter.peek().is_some() { + println!("\nPacman backup configuration files found:"); + + for entry in iter { + println!("{}", entry.path().display()); + } + } } fn upgrade_arch_linux(sudo: &Option, terminal: &mut Terminal, dry_run: bool) -> Result<(), failure::Error> { diff --git a/src/main.rs b/src/main.rs index 11b31ead..a6c4862e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,6 +15,7 @@ extern crate log; extern crate env_logger; extern crate term_size; extern crate termcolor; +extern crate walkdir; #[cfg(target_os = "linux")] mod linux; @@ -114,7 +115,7 @@ fn run() -> Result<(), Error> { #[cfg(target_os = "linux")] { if !opt.no_system { - match distribution { + match &distribution { Ok(distribution) => { report.push_result(execute( |terminal| distribution.upgrade(&sudo, terminal, opt.dry_run), @@ -302,6 +303,13 @@ fn run() -> Result<(), Error> { for (key, succeeded) in report.data() { terminal.print_result(key, *succeeded); } + + #[cfg(target_os = "linux")] + { + if let Ok(distribution) = &distribution { + distribution.show_summary(); + } + } } if report.data().iter().all(|(_, succeeded)| *succeeded) {