Add option to not ignore hard links (#273)
This commit is contained in:
parent
814bd116c6
commit
4c770b582b
|
@ -30,6 +30,8 @@ pub enum Commands {
|
||||||
file_to_save: FileToSave,
|
file_to_save: FileToSave,
|
||||||
#[structopt(flatten)]
|
#[structopt(flatten)]
|
||||||
not_recursive: NotRecursive,
|
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")]
|
#[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 {
|
EmptyFolders {
|
||||||
|
@ -227,6 +229,12 @@ pub struct FileToSave {
|
||||||
pub file_to_save: Option<PathBuf>,
|
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 {
|
impl FileToSave {
|
||||||
pub fn file_name(&self) -> Option<&str> {
|
pub fn file_name(&self) -> Option<&str> {
|
||||||
if let Some(file_name) = &self.file_to_save {
|
if let Some(file_name) = &self.file_to_save {
|
||||||
|
|
|
@ -39,6 +39,7 @@ fn main() {
|
||||||
hash_type,
|
hash_type,
|
||||||
file_to_save,
|
file_to_save,
|
||||||
not_recursive,
|
not_recursive,
|
||||||
|
allow_hard_links,
|
||||||
} => {
|
} => {
|
||||||
let mut df = DuplicateFinder::new();
|
let mut df = DuplicateFinder::new();
|
||||||
|
|
||||||
|
@ -51,6 +52,7 @@ fn main() {
|
||||||
df.set_delete_method(delete_method);
|
df.set_delete_method(delete_method);
|
||||||
df.set_hash_type(hash_type);
|
df.set_hash_type(hash_type);
|
||||||
df.set_recursive_search(!not_recursive.not_recursive);
|
df.set_recursive_search(!not_recursive.not_recursive);
|
||||||
|
df.set_ignore_hard_links(!allow_hard_links.allow_hard_links);
|
||||||
|
|
||||||
df.find_duplicates(None, None);
|
df.find_duplicates(None, None);
|
||||||
|
|
||||||
|
|
|
@ -148,6 +148,7 @@ pub struct DuplicateFinder {
|
||||||
check_method: CheckingMethod,
|
check_method: CheckingMethod,
|
||||||
delete_method: DeleteMethod,
|
delete_method: DeleteMethod,
|
||||||
hash_type: HashType,
|
hash_type: HashType,
|
||||||
|
ignore_hard_links: bool,
|
||||||
stopped_search: bool,
|
stopped_search: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,6 +168,7 @@ impl DuplicateFinder {
|
||||||
directories: Directories::new(),
|
directories: Directories::new(),
|
||||||
excluded_items: ExcludedItems::new(),
|
excluded_items: ExcludedItems::new(),
|
||||||
stopped_search: false,
|
stopped_search: false,
|
||||||
|
ignore_hard_links: true,
|
||||||
hash_type: HashType::Blake3,
|
hash_type: HashType::Blake3,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -237,6 +239,10 @@ impl DuplicateFinder {
|
||||||
self.hash_type = hash_type;
|
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) {
|
pub fn set_check_method(&mut self, check_method: CheckingMethod) {
|
||||||
self.check_method = check_method;
|
self.check_method = check_method;
|
||||||
}
|
}
|
||||||
|
@ -596,7 +602,14 @@ impl DuplicateFinder {
|
||||||
if vec.len() <= 1 {
|
if vec.len() <= 1 {
|
||||||
continue;
|
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 {
|
if vector.len() > 1 {
|
||||||
self.information.number_of_duplicated_files_by_size += vector.len() - 1;
|
self.information.number_of_duplicated_files_by_size += vector.len() - 1;
|
||||||
self.information.number_of_groups_by_size += 1;
|
self.information.number_of_groups_by_size += 1;
|
||||||
|
|
Loading…
Reference in a new issue