From 4c770b582bddaa0c4bcef4dad21fc09feacd4d3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Mikrut?= <41945903+qarmin@users.noreply.github.com> Date: Mon, 22 Feb 2021 20:14:33 +0100 Subject: [PATCH] Add option to not ignore hard links (#273) --- czkawka_cli/src/commands.rs | 8 ++++++++ czkawka_cli/src/main.rs | 2 ++ czkawka_core/src/duplicate.rs | 15 ++++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/czkawka_cli/src/commands.rs b/czkawka_cli/src/commands.rs index abda895..ed314f0 100644 --- a/czkawka_cli/src/commands.rs +++ b/czkawka_cli/src/commands.rs @@ -30,6 +30,8 @@ pub enum Commands { file_to_save: FileToSave, #[structopt(flatten)] not_recursive: NotRecursive, + #[structopt(flatten)] + allow_hard_links: AllowHardLinks, }, #[structopt(name = "empty-folders", about = "Finds empty folders", help_message = HELP_MESSAGE, after_help = "EXAMPLE:\n czkawka empty-folders -d /home/rafal/rr /home/gateway -f results.txt")] EmptyFolders { @@ -227,6 +229,12 @@ pub struct FileToSave { pub file_to_save: Option, } +#[derive(Debug, StructOpt)] +pub struct AllowHardLinks { + #[structopt(short = "L", long, help = "Do not ignore hard links")] + pub allow_hard_links: bool, +} + impl FileToSave { pub fn file_name(&self) -> Option<&str> { if let Some(file_name) = &self.file_to_save { diff --git a/czkawka_cli/src/main.rs b/czkawka_cli/src/main.rs index e599813..b74cc0b 100644 --- a/czkawka_cli/src/main.rs +++ b/czkawka_cli/src/main.rs @@ -39,6 +39,7 @@ fn main() { hash_type, file_to_save, not_recursive, + allow_hard_links, } => { let mut df = DuplicateFinder::new(); @@ -51,6 +52,7 @@ fn main() { df.set_delete_method(delete_method); df.set_hash_type(hash_type); df.set_recursive_search(!not_recursive.not_recursive); + df.set_ignore_hard_links(!allow_hard_links.allow_hard_links); df.find_duplicates(None, None); diff --git a/czkawka_core/src/duplicate.rs b/czkawka_core/src/duplicate.rs index 5e6f089..65e2359 100644 --- a/czkawka_core/src/duplicate.rs +++ b/czkawka_core/src/duplicate.rs @@ -148,6 +148,7 @@ pub struct DuplicateFinder { check_method: CheckingMethod, delete_method: DeleteMethod, hash_type: HashType, + ignore_hard_links: bool, stopped_search: bool, } @@ -167,6 +168,7 @@ impl DuplicateFinder { directories: Directories::new(), excluded_items: ExcludedItems::new(), stopped_search: false, + ignore_hard_links: true, hash_type: HashType::Blake3, } } @@ -237,6 +239,10 @@ impl DuplicateFinder { self.hash_type = hash_type; } + pub fn set_ignore_hard_links(&mut self, ignore_hard_links: bool) { + self.ignore_hard_links = ignore_hard_links; + } + pub fn set_check_method(&mut self, check_method: CheckingMethod) { self.check_method = check_method; } @@ -596,7 +602,14 @@ impl DuplicateFinder { if vec.len() <= 1 { continue; } - let vector = filter_hard_links(vec); + + let vector; + if self.ignore_hard_links { + vector = filter_hard_links(vec); + } else { + vector = vec.clone(); + } + if vector.len() > 1 { self.information.number_of_duplicated_files_by_size += vector.len() - 1; self.information.number_of_groups_by_size += 1;