Skip to content

Commit

Permalink
Guard the stdout when dumping groups of duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
netaneld122 committed Apr 5, 2020
1 parent ebaa54a commit c466275
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
3 changes: 3 additions & 0 deletions src/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -128,13 +129,15 @@ pub fn run<P>(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<u64> = map.keys().cloned().collect();
// Iterate through size groups simultaneously
keys.par_iter().for_each(|size: &u64| {
let same_size_paths = &map[size];
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());
Expand Down
4 changes: 2 additions & 2 deletions src/dirlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand All @@ -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()));
}
Expand Down

0 comments on commit c466275

Please sign in to comment.