Add threading (1th for input, 1th for output)
parent
f97430c21a
commit
19fcd69cb0
56
src/main.rs
56
src/main.rs
|
@ -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,33 +203,43 @@ fn main() {
|
|||
}
|
||||
|
||||
// Walk through path 1 & 2 [Todo: threading]
|
||||
for s in &[&args.input, &args.output] {
|
||||
for entry in WalkDir::new(&s)
|
||||
.into_iter()
|
||||
.filter_map(|e| e.ok())
|
||||
{
|
||||
// symlink_metadata does not follow symlink :-]
|
||||
let metadata = fs::symlink_metadata(entry.path()).unwrap();
|
||||
let ft = metadata.file_type();
|
||||
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())
|
||||
{
|
||||
// symlink_metadata does not follow symlink :-]
|
||||
let metadata = fs::symlink_metadata(entry.path()).unwrap();
|
||||
let ft = metadata.file_type();
|
||||
|
||||
if ft.is_file() {
|
||||
if let Ok(mut file) = fs::File::open(&entry.path()) {
|
||||
let mut a = FileToProcess {
|
||||
name: format!("{}",
|
||||
entry.path().display()),
|
||||
hash: vec![],
|
||||
realpath: String::from("TODO"),
|
||||
};
|
||||
if ft.is_file() {
|
||||
if let Ok(mut file) = fs::File::open(&entry.path()) {
|
||||
let mut a = FileToProcess {
|
||||
name: format!("{}",
|
||||
entry.path().display()),
|
||||
hash: vec![],
|
||||
realpath: String::from("TODO"),
|
||||
};
|
||||
|
||||
// compute file hash
|
||||
a.hash::<Sha256, _>(&mut file);
|
||||
files_candidate.push(a);
|
||||
// compute file hash
|
||||
a.hash::<Sha256, _>(&mut file);
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue