-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement vast improvements in error handling. Squashed commit of the following: commit bdb0d105b00d854c78d4ccd0a94aec471aeed652 Author: Olivier Thornton <[email protected]> Date: Thu Feb 16 13:45:35 2023 -0600 disable debug mode commit 0dc4f9f Author: Olivier Thornton <[email protected]> Date: Thu Feb 16 13:40:34 2023 -0600 update readme commit 9fd8f28 Author: Olivier Thornton <[email protected]> Date: Thu Feb 16 13:40:27 2023 -0600 error handling commit 8bc2fdf Author: Olivier Thornton <[email protected]> Date: Thu Feb 16 13:39:59 2023 -0600 update version info commit 805a785 Author: Olivier Thornton <[email protected]> Date: Thu Feb 16 12:34:54 2023 -0600 remove dot files from delete_all commit 723644d Author: Olivier Thornton <[email protected]> Date: Thu Feb 16 10:31:40 2023 -0600 update error messages commit 7d21b55 Author: Olivier Thornton <[email protected]> Date: Thu Feb 16 10:16:43 2023 -0600 error handling in deleting dir commit d1383ce Author: Olivier Thornton <[email protected]> Date: Thu Feb 16 09:53:03 2023 -0600 handle cannot read directory error commit 4747338 Author: Olivier Thornton <[email protected]> Date: Thu Feb 16 09:52:47 2023 -0600 handle cannot open file error commit 462f48f Author: Olivier Thornton <[email protected]> Date: Thu Feb 16 09:41:06 2023 -0600 error handling for parsing number of passes commit d4b7e28 Author: Olivier Thornton <[email protected]> Date: Thu Feb 16 08:42:41 2023 -0600 really fix subtract with overflow commit f73fcd8 Author: Olivier Thornton <[email protected]> Date: Wed Feb 15 11:35:00 2023 -0600 remove unnecessary nested if statement commit 91dc2fd Author: Olivier Thornton <[email protected]> Date: Wed Feb 15 11:30:45 2023 -0600 update constants to pull some values from Cargo.toml commit d17e44e Author: Olivier Thornton <[email protected]> Date: Wed Feb 15 11:30:31 2023 -0600 fix subtract with overflow Fix a bug where if passed a single argument that was invalid, the program would attempt to subtract from the args to get a possible number of passes, resulting in overflow.
- Loading branch information
Olivier Thornton
committed
Feb 16, 2023
1 parent
e5b2ff4
commit 64f2665
Showing
13 changed files
with
212 additions
and
118 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "secure_remove" | ||
version = "2.2.2" | ||
version = "2.2.3" | ||
edition = "2021" | ||
authors = ["Olivier Thornton <[email protected]>"] | ||
description = "Securely remove files and directories" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
pub const DEBUG: bool = false; | ||
const VERSION: &str = "2.2.2"; | ||
const AUTHOR: &str = "Olivier Thornton"; | ||
const VERSION: &str = env!("CARGO_PKG_VERSION"); | ||
const AUTHOR: &str = env!("CARGO_PKG_AUTHORS"); | ||
const LICENSE: &str = "GPLV3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>."; | ||
|
||
pub fn version() { | ||
println!("srm v{}", VERSION); | ||
println!("Secure Remove v{}", VERSION); | ||
println!("License {}", LICENSE); | ||
println!("This is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law."); | ||
println!("\nWritten by {}.", AUTHOR); | ||
} | ||
|
||
pub fn help() { | ||
println!("Usage: srm [OPTION]... FILE..."); | ||
println!("Usage: srm [OPTION]... FILE(s)..."); | ||
println!("Securely remove files or directories.\n"); | ||
println!(" -r, --recursive\tremove directories and their contents recursively"); | ||
println!(" -p, --passes\t\tset the number of passes (default: 10)"); | ||
println!(" -p, --passes\t\tset the number of passes (default: 40)"); | ||
println!(" -v, --verbose\t\texplain what is being done"); | ||
println!(" --help\t\tdisplay this help and exit"); | ||
println!(" --version\t\toutput version information and exit"); | ||
println!("\nBy default, srm does not remove directories. Use the --recursive (-r)"); | ||
println!("option to remove each listed directory, too, along with all of its contents.") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use crate::shred::{delete_folder::delete_folder, shred_file::shred_file}; | ||
use std::{fs, path::Path}; | ||
|
||
pub fn delete_all(passes: u32, verbose: bool, recursive: bool) { | ||
// get all files and folders in the working directory as a vector of strings | ||
let entries_raw = match fs::read_dir(".") { | ||
Ok(entries) => entries, | ||
Err(_) => { | ||
println!( | ||
"'{}': failed to read directory", | ||
std::env::current_dir().unwrap().to_string_lossy() | ||
); | ||
std::process::exit(0); | ||
} | ||
}; | ||
let mut entries: Vec<String> = Vec::new(); | ||
for entry in entries_raw { | ||
let temp = entry.unwrap().file_name().to_string_lossy().to_string(); | ||
// if the entry does not begin with a dot, add it to the vector | ||
if !temp.starts_with('.') { | ||
entries.push(temp); | ||
} | ||
} | ||
|
||
for entry in entries { | ||
let path = Path::new(&entry); | ||
if path.is_file() { | ||
shred_file(&entry, passes, verbose); | ||
} else if path.is_dir() && recursive { | ||
match delete_folder(&entry, passes, verbose) { | ||
Ok(_) => { | ||
if verbose { | ||
print!("Deleting directory '{}' . . .\t\t", entry); | ||
} | ||
// delete the directory | ||
match fs::remove_dir_all(&entry) { | ||
Ok(_) => { | ||
if verbose { | ||
println!("Done"); | ||
} | ||
} | ||
Err(e) => { | ||
println!("'{}': {}", entry, e); | ||
continue; | ||
} | ||
}; | ||
} | ||
Err(_) => { | ||
println!("'{}': Failed to delete directory", entry); | ||
continue; | ||
} | ||
}; | ||
} else if path.is_dir() && !recursive { | ||
println!("srm: cannot remove '{}': Is a directory", entry); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use crate::{config::constants, shred::shred_file::shred_file}; | ||
use std::fs; | ||
|
||
pub fn delete_folder(path: &String, passes: u32, verbose: bool) -> Result<(), std::io::Error> { | ||
if constants::DEBUG { | ||
println!("- DEBUG - Deleting folder: '{}'", path); | ||
} | ||
|
||
// get all files and folders in the directory | ||
let entries = match fs::read_dir(path) { | ||
Ok(entries) => entries, | ||
Err(_) => { | ||
return Err(std::io::Error::new( | ||
std::io::ErrorKind::Other, | ||
"Failed to read directory", | ||
)); | ||
} | ||
}; | ||
|
||
// loop through the files | ||
for entry in entries { | ||
let object = entry?; | ||
|
||
if constants::DEBUG { | ||
println!("- DEBUG - File: {}", &object.file_name().to_string_lossy()); | ||
} | ||
|
||
if object.file_type()?.is_dir() { | ||
// create the full path to the directory | ||
let new_path = path.to_string() + "/" + &object.file_name().to_string_lossy(); | ||
|
||
match delete_folder(&new_path, passes, verbose) { | ||
Ok(_) => { | ||
if verbose { | ||
print!("Deleting directory '{}' . . .\t\t", new_path); | ||
} | ||
|
||
// delete the directory | ||
match fs::remove_dir_all(&new_path) { | ||
Ok(_) => { | ||
if verbose { | ||
println!("Done"); | ||
} | ||
} | ||
Err(e) => { | ||
println!("'{}': {}", new_path, e); | ||
continue; | ||
} | ||
}; | ||
} | ||
Err(_) => { | ||
println!("'{}': Failed to delete directory", new_path); | ||
continue; | ||
} | ||
} | ||
} else if object.file_type().unwrap().is_file() { | ||
// create the full path to the file | ||
let new_path = path.to_string() + "/" + &object.file_name().to_string_lossy(); | ||
|
||
shred_file(&new_path, passes, verbose); | ||
} | ||
} | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod delete_all; | ||
pub mod delete_folder; | ||
pub mod shred_file; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.