Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to not ignore hard links #273

Merged
merged 1 commit into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions czkawka_cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -227,6 +229,12 @@ pub struct FileToSave {
pub file_to_save: Option<PathBuf>,
}

#[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 {
Expand Down
2 changes: 2 additions & 0 deletions czkawka_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ fn main() {
hash_type,
file_to_save,
not_recursive,
allow_hard_links,
} => {
let mut df = DuplicateFinder::new();

Expand All @@ -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);

Expand Down
15 changes: 14 additions & 1 deletion czkawka_core/src/duplicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ pub struct DuplicateFinder {
check_method: CheckingMethod,
delete_method: DeleteMethod,
hash_type: HashType,
ignore_hard_links: bool,
stopped_search: bool,
}

Expand All @@ -167,6 +168,7 @@ impl DuplicateFinder {
directories: Directories::new(),
excluded_items: ExcludedItems::new(),
stopped_search: false,
ignore_hard_links: true,
hash_type: HashType::Blake3,
}
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down