From 7b8a134db974d3caf491d858f472385688aae8f9 Mon Sep 17 00:00:00 2001 From: Amy Date: Sat, 25 Dec 2021 14:44:46 +0100 Subject: [PATCH] doesnt backup existing binaries/scripts anymore Instead it just skips creating it when a file with the name already exists --- src/main.rs | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/src/main.rs b/src/main.rs index 015d358..2a3f722 100644 --- a/src/main.rs +++ b/src/main.rs @@ -76,31 +76,12 @@ pub fn add_mngrs(pkg_managers: Vec>, proper_manager: String) { pub fn create_script() { let connection = sqlite::open("/usr/share/pkg_warner/pkg_mngrs.db").unwrap(); - let path = std::path::Path::new("/usr/share/pkg_warner/backs/"); let result = connection.iterate( format!("SELECT mngr FROM pkg_mngrs WHERE mngr IS NOT \"proper_manager\";"), |pairs| { for &(_column, value) in pairs.iter() { if std::path::Path::new(&format!("/usr/bin/{}", value.unwrap())).exists() { - if !path.is_dir() { - let result = std::fs::create_dir_all("/usr/share/pkg_warner/backs/".to_string()); - match result { - Ok(_) => { - println!("Created path for binary backups (previously missing)"); - } - Err(_) => { - println!("Couldn't create path for binary backups (/usr/share/pkg_warner/backs)") - } - } - } - let result = std::fs::copy(&format!("/usr/bin/{}", value.unwrap()), &format!("/usr/share/pkg_warner/backs/{}", value.unwrap())); - match result { - Ok(_) => { - } - Err(_) => { - println!("Couldn't back up {}", value.unwrap()); - } - } + println!("Skipped {}, as it already exists", value.unwrap()); } writeln!(&mut fs::File::create(format!("/usr/bin/{}",value.unwrap())).unwrap(), "#!/usr/bin/env bash\n pkg-warner -w {}", value.unwrap()).unwrap(); Command::new("chmod") @@ -278,4 +259,4 @@ fn main() { help(); } } -} \ No newline at end of file +}