1
0
Fork 0
mirror of synced 2024-04-27 09:12:06 +12:00

Add option to not ignore hard links (#273)

This commit is contained in:
Rafał Mikrut 2021-02-22 20:14:33 +01:00 committed by GitHub
parent 814bd116c6
commit 4c770b582b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 1 deletions

View file

@ -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<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 {

View file

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

View file

@ -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;