summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Moroney <darakian@gmail.com>2022-01-23 15:05:46 -0800
committerJon Moroney <darakian@gmail.com>2022-01-23 15:05:46 -0800
commitd8930399753a442eaf1ebf8fa172dfae88f10ef9 (patch)
treeb4e4de09b11a5b97299ffc296b6858204c08e2b1
parentf566fecf478208e17eb3384699fbde85ce1a6e6b (diff)
Wire up min size for filesupdate-to-clap3
-rw-r--r--src/lib.rs15
-rw-r--r--src/main.rs3
2 files changed, 12 insertions, 6 deletions
diff --git a/src/lib.rs b/src/lib.rs
index f2cc3d4..7cb6333 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -27,11 +27,16 @@ enum ChannelPackage {
pub fn deduplicate_dirs<P: AsRef<Path> + Sync>(
search_dirs: Vec<P>,
) -> (Vec<Fileinfo>, Vec<(PathBuf, std::io::Error)>) {
+ deduplicate_dirs_with_min(search_dirs, 0)
+}
+
+pub fn deduplicate_dirs_with_min<P: AsRef<Path> + Sync>(
+ search_dirs: Vec<P>, min_size: u64) -> (Vec<Fileinfo>, Vec<(PathBuf, std::io::Error)>) {
let (sender, receiver) = channel();
search_dirs
.par_iter()
.for_each_with(sender, |s, search_dir| {
- traverse_and_spawn(search_dir.as_ref(), s.clone());
+ traverse_and_spawn(search_dir.as_ref(), s.clone(), min_size);
});
let mut files_of_lengths: IntMap<u64, Vec<Fileinfo>> = IntMap::default();
let mut errors = Vec::new();
@@ -56,7 +61,7 @@ pub fn deduplicate_dirs<P: AsRef<Path> + Sync>(
(complete_files, errors)
}
-fn traverse_and_spawn(current_path: impl AsRef<Path>, sender: Sender<ChannelPackage>) {
+fn traverse_and_spawn(current_path: impl AsRef<Path>, sender: Sender<ChannelPackage>, min_size: u64) {
let current_path_metadata = match fs::symlink_metadata(&current_path) {
Err(e) => {
sender
@@ -76,7 +81,7 @@ fn traverse_and_spawn(current_path: impl AsRef<Path>, sender: Sender<ChannelPack
Ok(canonical_path) => canonical_path,
};
match current_path_metadata {
- meta if meta.is_file() => {
+ meta if meta.is_file() && meta.len() >= min_size => {
sender
.send(ChannelPackage::Success(Fileinfo::new(
None,
@@ -99,10 +104,10 @@ fn traverse_and_spawn(current_path: impl AsRef<Path>, sender: Sender<ChannelPack
.is_file()
});
files.par_iter().for_each_with(sender.clone(), |sender, x| {
- traverse_and_spawn(&x.path(), sender.clone())
+ traverse_and_spawn(&x.path(), sender.clone(), min_size)
});
dirs.into_par_iter().for_each_with(sender, |sender, x| {
- traverse_and_spawn(x.path().as_path(), sender.clone());
+ traverse_and_spawn(x.path().as_path(), sender.clone(), min_size);
})
}
Err(e) => {
diff --git a/src/main.rs b/src/main.rs
index 9b33751..ecb9ac1 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -74,9 +74,10 @@ fn main() {
//let (sender, receiver) = channel();
let search_dirs: Vec<_> = arguments.values_of("directories").unwrap().collect();
+ let min_size: u64 = arguments.value_of("Minimum").unwrap().parse::<u64>().unwrap_or(0);
let (complete_files, read_errors): (Vec<Fileinfo>, Vec<(_, _)>) =
- ddh::deduplicate_dirs(search_dirs);
+ ddh::deduplicate_dirs_with_min(search_dirs, min_size);
let (shared_files, unique_files): (Vec<&Fileinfo>, Vec<&Fileinfo>) = complete_files
.par_iter()
.partition(|&x| x.get_paths().len() > 1);