Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Options:
-t, --threads <THREADS> [default: 0]
-v, --verbose
--urandom
--dry-run Simulate operation without writing data
-h, --help Print help
-V, --version Print version
```
Expand Down
14 changes: 10 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ struct Args {

#[arg(long, default_value_t = false)]
urandom: bool,

#[arg(long, default_value_t = false, help = "Simulate operation without writing data")]
dry_run: bool,
}

fn process_file(path: &Path, verbose: bool, random_source: RandomSource) -> Result<()> {
fn process_file(path: &Path, verbose: bool, random_source: RandomSource, dry_run: bool) -> Result<()> {
if verbose { println!("Processing: {}", path.display()); }

let meta = std::fs::metadata(path)
Expand All @@ -42,15 +45,18 @@ fn process_file(path: &Path, verbose: bool, random_source: RandomSource) -> Resu
return Ok(());
}

file_ops::overwrite_with_random(path, size, random_source)
.with_context(|| format!("Failed to overwrite {}", path.display()))?;
if !dry_run {
file_ops::overwrite_with_random(path, size, random_source)
.with_context(|| format!("Failed to overwrite {}", path.display()))?;
}

if verbose { println!("Successful {}", path.display()); }
Ok(())
}

fn main() -> Result<()> {
let args = Args::parse();
if args.dry_run { eprintln!("[!] DRY-RUN MODE: No data will be written.") }
let random_source = if args.urandom { RandomSource::Urandom } else { RandomSource::Random };

let mut files = Vec::new();
Expand Down Expand Up @@ -86,7 +92,7 @@ fn main() -> Result<()> {
let errors = std::sync::Mutex::new(Vec::<(PathBuf, String)>::new());

files.par_iter().for_each(|path| {
let res = process_file(path, args.verbose, random_source);
let res = process_file(path, args.verbose, random_source, args.dry_run);
let count = processed.fetch_add(1, Ordering::Relaxed) + 1;

if let Err(e) = res {
Expand Down
Loading