From f97430c21ae8b4825d5c754648c8c97f359e494c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Mauduit?= Date: Wed, 2 May 2018 23:12:18 +0200 Subject: [PATCH] Compute hash for both directory and store result in a vec --- src/main.rs | 75 +++++++++++++++++++++++------------------------------ 1 file changed, 32 insertions(+), 43 deletions(-) diff --git a/src/main.rs b/src/main.rs index f281822..ecb218e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,9 +65,7 @@ impl Args { } fn check_not_parent(&self) -> bool { - let vec = vec![&self.input, &self.output]; - - for (i, x) in vec.iter().enumerate() { + for (i, x) in vec![&self.input, &self.output].iter().enumerate() { let mut a = Path::new(x); let tmp = match i { 0 => &self.output, @@ -172,16 +170,15 @@ fn main() { t.fg(term::color::GREEN).unwrap(); let args = Args::new(&matches); - println!("Value for input: {}", args.input); - println!("Value for output: {}", args.output); - println!("Verbosity Level: {}", args.vlevel); - - if args.dryrun { - println!("dry-run enabled"); - } else if args.vlevel >= 2 { - t.fg(term::color::RED).unwrap(); - println!("dry-run not enabled"); - t.reset().unwrap(); + if args.vlevel >= 2 { + println!("Value for input: {}", args.input); + println!("Value for output: {}", args.output); + println!("Verbosity Level: {}", args.vlevel); + if args.dryrun { + println!("dry-run enabled"); + } else if args.vlevel >= 2 { + println!("dry-run not enabled"); + } } // Check input & output @@ -203,26 +200,29 @@ fn main() { process::exit(1); } - // Output - for entry in WalkDir::new(&args.output) - .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(); + // 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(); - 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"), - }; - a.hash::(&mut file); - println!("{}", a); - files_candidate.push(a); + 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::(&mut file); + files_candidate.push(a); + } } } } @@ -231,17 +231,6 @@ fn main() { println!("{}", i); } - - // let inputs = fs::read_dir(&args.input).unwrap(); - // for path in inputs { - // let path_str = path.unwrap().path().into_os_string().into_string().unwrap(); - // println!("[I] Name: {}", path_str); - // if let Ok(mut file) = fs::File::open(&path_str) { - // process::(&mut file, - // &path_str); - // } - // } - t.reset().unwrap(); t.fg(term::color::CYAN).unwrap(); println!("Cheers !");