From c466275b05f32fcf26b7c3292a1238a9bae19040 Mon Sep 17 00:00:00 2001 From: netaneld122 Date: Sun, 5 Apr 2020 12:20:32 +0300 Subject: [PATCH] Guard the stdout when dumping groups of duplicates --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/algorithm.rs | 3 +++ src/dirlist.rs | 4 ++-- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1f52520..bac1d53 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -145,7 +145,7 @@ dependencies = [ [[package]] name = "ddup" -version = "0.0.3" +version = "0.0.4" dependencies = [ "clap", "crc", diff --git a/Cargo.toml b/Cargo.toml index 399b975..362f588 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ddup" -version = "0.0.3" +version = "0.0.4" description = "Tool that detects potentially duplicated files in Windows NTFS volumes" license = "MIT" authors = ["netaneld122"] diff --git a/src/algorithm.rs b/src/algorithm.rs index 2b999cb..f0c56ed 100644 --- a/src/algorithm.rs +++ b/src/algorithm.rs @@ -5,6 +5,7 @@ use std::path::{Path, PathBuf}; use std::cmp::min; use std::ops::FnMut; use std::time::Instant; +use std::sync::{Mutex}; use crc::{crc32, Hasher32}; @@ -128,6 +129,7 @@ pub fn run

(drive: &str, filter: P, comparison: Comparison) println!("[3/3] Grouping by hash in thread pool"); // Print all duplicates + let stdout_mutex = Mutex::new(0); let keys: Vec = map.keys().cloned().collect(); // Iterate through size groups simultaneously keys.par_iter().for_each(|size: &u64| { @@ -135,6 +137,7 @@ pub fn run

(drive: &str, filter: P, comparison: Comparison) for same_crc_paths in reduce_by_content(*size, &same_size_paths, &comparison).into_iter() { + let _guard = stdout_mutex.lock(); println!("Potential duplicates [{} bytes]", size); for path in same_crc_paths { println!("\t{}", path.to_str().unwrap()); diff --git a/src/dirlist.rs b/src/dirlist.rs index f8d639f..5e2f871 100644 --- a/src/dirlist.rs +++ b/src/dirlist.rs @@ -50,7 +50,7 @@ mod tests { println!("What is this\r\n"); let instant = Instant::now(); let mut v1 = Vec::new(); - for p in walkdir::WalkDir::new(r"G:\") { + for p in walkdir::WalkDir::new(r"C:\") { if let Ok(d) = p { if d.file_type().is_file() { v1.push(String::from(d.path().to_str().unwrap())); @@ -61,7 +61,7 @@ mod tests { let instant = Instant::now(); let mut v2 = Vec::new(); - let dirlist = DirList::new("G:").unwrap(); + let dirlist = DirList::new("C:").unwrap(); for p in dirlist.iter() { v2.push(String::from(p.to_str().unwrap())); }