summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Moroney <darakian@gmail.com>2020-08-23 15:13:47 -0700
committerGitHub <noreply@github.com>2020-08-23 15:13:47 -0700
commit1f5ee5a61aee60371cb0c2e8c99c67c97d41b7d1 (patch)
treed64a4e898d14a8407fc0822fee8278c36edaadea
parentf33e299963458cbd834ca7b7f12bd57f23acd9b4 (diff)
parentc9abf2bca4f1944e8e7c2699537b4187ec1acdee (diff)
Merge pull request #44 from darakian/masterrelease
Merge master at 0.11.3 to release
-rw-r--r--Cargo.toml2
-rw-r--r--src/lib.rs92
2 files changed, 44 insertions, 50 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 6ce3869..43bbf04 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "ddh"
-version = "0.11.2"
+version = "0.11.3"
authors = ["Jon Moroney <jmoroney@hawaii.edu>"]
edition = "2018"
description = "Compare and contrast directories"
diff --git a/src/lib.rs b/src/lib.rs
index 6ade0ff..4908958 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -10,7 +10,6 @@ use std::path::{PathBuf, Path};
use rayon::prelude::*;
use std::sync::mpsc::{Sender, channel};
use std::collections::hash_map::{HashMap, Entry};
-use std::io::{Error, ErrorKind};
use nohash_hasher::IntMap;
enum ChannelPackage{
@@ -53,69 +52,64 @@ pub fn deduplicate_dirs<P: AsRef<Path> + Sync>(search_dirs: Vec<P>) -> (Vec<File
(complete_files, errors)
}
-fn traverse_and_spawn(current_path: &Path, sender: Sender<ChannelPackage>) -> (){
- let current_path_metadata = match fs::symlink_metadata(current_path) {
+fn traverse_and_spawn(current_path: impl AsRef<Path>, sender: Sender<ChannelPackage>) -> (){
+ let current_path_metadata = match fs::symlink_metadata(&current_path) {
Err(e) =>{
sender.send(
- ChannelPackage::Fail(current_path.to_path_buf(), e)
+ ChannelPackage::Fail(current_path.as_ref().to_path_buf(), e)
).expect("Error sending new ChannelPackage::Fail");
return
},
Ok(meta) => meta,
};
-
- if current_path_metadata.file_type().is_symlink(){
- sender.send(
- ChannelPackage::Fail(current_path.to_path_buf(), Error::new(ErrorKind::Other, "Path is symlink"))
- ).expect("Error sending new ChannelPackage::Fail");
- return
- }
-
- if current_path_metadata.file_type().is_file(){
+ let current_path = match fs::canonicalize(&current_path) {
+ Err(e) => {
+ sender.send(
+ ChannelPackage::Fail(current_path.as_ref().to_path_buf(), e)
+ ).expect("Error sending new ChannelPackage::Fail");
+ return
+ },
+ Ok(canonical_path) => canonical_path,
+ };
+ match current_path_metadata{
+ meta if meta.is_file() => {
sender.send(ChannelPackage::Success(
Fileinfo::new(
None,
None,
- current_path.metadata().expect("Error reading file metadata"),
+ meta,
current_path.to_path_buf()
))
).expect("Error sending new ChannelPackage::Success");
- return
- }
-
- if current_path_metadata.file_type().is_dir(){
- match fs::read_dir(current_path) {
- Ok(read_dir_results) => {
- let good_entries: Vec<_> = read_dir_results
- .filter(|x| x.is_ok())
- .map(|x| x.unwrap())
- .collect();
- let (files, dirs): (Vec<&DirEntry>, Vec<&DirEntry>) = good_entries.par_iter().partition(|&x|
- x.file_type()
- .expect("Error reading DirEntry file type")
- .is_file()
- );
- files.par_iter().for_each_with(sender.clone(), |sender, x|
- sender.send(ChannelPackage::Success(
- Fileinfo::new(
- None,
- None,
- current_path.metadata().expect("Error reading file metadata"),
- x.path()))
- ).expect("Error sending new ChannelPackage::Success")
+ },
+ meta if meta.is_dir() => {
+ match fs::read_dir(&current_path) {
+ Ok(read_dir_results) => {
+ let good_entries: Vec<_> = read_dir_results
+ .filter(|x| x.is_ok())
+ .map(|x| x.unwrap())
+ .collect();
+ let (files, dirs): (Vec<&DirEntry>, Vec<&DirEntry>) = good_entries.par_iter().partition(|&x|
+ x.file_type()
+ .expect("Error reading DirEntry file type")
+ .is_file()
);
- dirs.into_par_iter()
- .for_each_with(sender, |sender, x| {
- traverse_and_spawn(x.path().as_path(), sender.clone());
- })
- },
- Err(e) => {
- sender.send(
- ChannelPackage::Fail(current_path.to_path_buf(), e)
- ).expect("Error sending new ChannelPackage::Fail");
- },
- }
- } else {}
+ files.par_iter().for_each_with(sender.clone(), |sender, x|
+ traverse_and_spawn(&x.path(), sender.clone()));
+ dirs.into_par_iter()
+ .for_each_with(sender, |sender, x| {
+ traverse_and_spawn(x.path().as_path(), sender.clone());
+ })
+ },
+ Err(e) => {
+ sender.send(
+ ChannelPackage::Fail(current_path.to_path_buf(), e)
+ ).expect("Error sending new ChannelPackage::Fail");
+ },
+ }
+ },
+ _ => {/*Symlinks not yet handled*/},
+ }
}
fn differentiate_and_consolidate(file_length: u64, mut files: Vec<Fileinfo>) -> Vec<Fileinfo>{