doesnt backup existing binaries/scripts anymore

Instead it just skips creating it when a file with the name already exists
main
Amy 2 years ago
parent 8e7b7cc3cb
commit 7b8a134db9
No known key found for this signature in database
GPG Key ID: 6672E6DD65BEA50B

@ -76,31 +76,12 @@ pub fn add_mngrs(pkg_managers: Vec<Vec<String>>, 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();
}
}
}
}

Loading…
Cancel
Save