Add threading (1th for input, 1th for output)

master
Benoît 2018-05-08 14:18:03 +02:00
parent f97430c21a
commit 19fcd69cb0
1 changed files with 34 additions and 22 deletions

View File

@ -11,6 +11,8 @@ use std::fs;
use std::io::Read;
use walkdir::WalkDir;
use std::fmt;
use std::thread;
use std::sync::{Arc, Mutex};
const BUFFER_SIZE: usize = 1024;
@ -134,7 +136,7 @@ impl FileToProcess {
}
fn main() {
let mut files_candidate = vec![];
let files_candidate = Arc::new(Mutex::new(Vec::new()));
let mut t = term::stdout().unwrap();
let matches = App::new("rdupe")
.version("0.1.0")
@ -201,7 +203,11 @@ fn main() {
}
// Walk through path 1 & 2 [Todo: threading]
for s in &[&args.input, &args.output] {
let mut children = vec![];
let args_source = vec![args.input, args.output];
for s in args_source {
let fc = files_candidate.clone();
children.push(thread::spawn(move || {
for entry in WalkDir::new(&s)
.into_iter()
.filter_map(|e| e.ok())
@ -221,13 +227,19 @@ fn main() {
// compute file hash
a.hash::<Sha256, _>(&mut file);
files_candidate.push(a);
fc.lock().unwrap().push(a);
}
}
}
}));
}
for i in files_candidate {
for child in children {
// Wait for the thread to finish. Returns a result.
let _ = child.join();
}
for i in files_candidate.lock().unwrap().iter() {
println!("{}", i);
}