From 6a626fabe6bfe1796a7882900a5abac84feb68be Mon Sep 17 00:00:00 2001 From: VeryBaaad Date: Mon, 20 Apr 2026 22:46:30 +0800 Subject: [PATCH 1/6] feat: add dry-run mode --- src/main.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 780e923..3d82467 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,9 +28,13 @@ struct Args { #[arg(long, default_value_t = false)] urandom: bool, + + #[arg(long, default_value_t = false, help = "Run without fill")] + dry_run: bool, } fn process_file(path: &Path, verbose: bool, random_source: RandomSource) -> Result<()> { + let args = Args::parse(); if verbose { println!("Processing: {}", path.display()); } let meta = std::fs::metadata(path) @@ -42,8 +46,10 @@ 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 !args.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(()) @@ -51,6 +57,7 @@ fn process_file(path: &Path, verbose: bool, random_source: RandomSource) -> Resu fn main() -> Result<()> { let args = Args::parse(); + if args.dry_run { println!("[DRY RUN] !Randfill is running in dry run mode") } let random_source = if args.urandom { RandomSource::Urandom } else { RandomSource::Random }; let mut files = Vec::new(); From a008123029ec1f22041256a460a709038a2c1262 Mon Sep 17 00:00:00 2001 From: VeryBaaad Date: Mon, 20 Apr 2026 22:57:00 +0800 Subject: [PATCH 2/6] refactor: pass dry_run as parameter to process_file - Remove Args::parse() call inside process_file to avoid redundant parsing - Add dry_run bool parameter for explicit dependency injection - Prepare for safe parallel execution in rayon threads --- src/main.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3d82467..a9d011e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,8 +33,7 @@ struct Args { dry_run: bool, } -fn process_file(path: &Path, verbose: bool, random_source: RandomSource) -> Result<()> { - let args = Args::parse(); +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) @@ -46,7 +45,7 @@ fn process_file(path: &Path, verbose: bool, random_source: RandomSource) -> Resu return Ok(()); } - if !args.dry_run { + if !dry_run { file_ops::overwrite_with_random(path, size, random_source) .with_context(|| format!("Failed to overwrite {}", path.display()))?; } @@ -93,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 { From 84526d82149aa54906e6a53a9fcfe92e168e3f9f Mon Sep 17 00:00:00 2001 From: VeryBaaad Date: Mon, 20 Apr 2026 22:58:56 +0800 Subject: [PATCH 3/6] docs(cli): improve --dry-run help text --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index a9d011e..55eb1a3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,7 +29,7 @@ struct Args { #[arg(long, default_value_t = false)] urandom: bool, - #[arg(long, default_value_t = false, help = "Run without fill")] + #[arg(long, default_value_t = false, help = "Simulate operation without writing data")] dry_run: bool, } From e1f4f2d1e981e5d314c27d55a99018cffe90b300 Mon Sep 17 00:00:00 2001 From: VeryBaaad Date: Mon, 20 Apr 2026 23:00:41 +0800 Subject: [PATCH 4/6] feat(cli): standardize dry-run output format --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 55eb1a3..b3736ca 100644 --- a/src/main.rs +++ b/src/main.rs @@ -56,7 +56,7 @@ fn process_file(path: &Path, verbose: bool, random_source: RandomSource, dry_run fn main() -> Result<()> { let args = Args::parse(); - if args.dry_run { println!("[DRY RUN] !Randfill is running in dry run mode") } + if args.dry_run { println!("[!] DRY-RUN MODE: No data will be written.") } let random_source = if args.urandom { RandomSource::Urandom } else { RandomSource::Random }; let mut files = Vec::new(); From 287495feb33771154aeeaee4f43fb348c2164eae Mon Sep 17 00:00:00 2001 From: VeryBaaad Date: Mon, 20 Apr 2026 23:02:16 +0800 Subject: [PATCH 5/6] feat(cli): use eprintln! for dry-run warning --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index b3736ca..960c79b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -56,7 +56,7 @@ fn process_file(path: &Path, verbose: bool, random_source: RandomSource, dry_run fn main() -> Result<()> { let args = Args::parse(); - if args.dry_run { println!("[!] DRY-RUN MODE: No data will be written.") } + 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(); From b980e0fdc6546634161ac89875cc86dc56334af6 Mon Sep 17 00:00:00 2001 From: VeryBaaad Date: Mon, 20 Apr 2026 23:14:40 +0800 Subject: [PATCH 6/6] docs: add dry-run help --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 89eab43..0311638 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ Options: -t, --threads [default: 0] -v, --verbose --urandom + --dry-run Simulate operation without writing data -h, --help Print help -V, --version Print version ```