Compute hash for both directory and store result in a vec

master
Benoît 2018-05-02 23:12:18 +02:00
parent 583d7f1b9c
commit f97430c21a
1 changed files with 32 additions and 43 deletions

View File

@ -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::<Sha256, _>(&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::<Sha256, _>(&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::<Sha256, _>(&mut file,
// &path_str);
// }
// }
t.reset().unwrap();
t.fg(term::color::CYAN).unwrap();
println!("Cheers !");