Minimal file size in duplicate finder should be always greater than 0

This commit is contained in:
Rafał Mikrut 2020-10-03 09:51:02 +02:00
parent a0c99ab14b
commit 8d263fdff2
3 changed files with 14 additions and 11 deletions

View File

@ -78,7 +78,7 @@ fn main() {
}
if ArgumentsPair::has_command(&arguments, "-s") {
let min_size = match ArgumentsPair::get_argument(&arguments, "-s", false).parse::<u64>() {
let minimal_file_size = match ArgumentsPair::get_argument(&arguments, "-s", false).parse::<u64>() {
Ok(t) => {
if t == 0 {
println!("ERROR: Minimum file size must be at least 1 byte.");
@ -92,7 +92,7 @@ fn main() {
process::exit(1);
}
};
df.set_min_file_size(min_size);
df.set_minimal_file_size(minimal_file_size);
}
if ArgumentsPair::has_command(&arguments, "-x") {
@ -364,7 +364,7 @@ fn print_help() {
[Main commands]:
--help / --h - prints help, also works without any arguments
--d <-i directories_to_search> [-e excluded_directories = ""] [-k excluded_items = ""] [-s min_size = 1024] [-x allowed_extension = ""] [-l type_of_search = "hash"] [-o] [-f file_to_save = "results.txt"] [-delete = "aeo"] - finds duplicates files
--d <-i directories_to_search> [-e excluded_directories = ""] [-k excluded_items = ""] [-s minimal_file_size = 1024] [-x allowed_extension = ""] [-l type_of_search = "hash"] [-o] [-f file_to_save = "results.txt"] [-delete = "aeo"] - finds duplicates files
--e <-i directories_to_search> [-e excluded_directories = ""] [-o] [-f file_to_save = "results.txt"] [-delete] - finds empty folders
--b <-i directories_to_search> [-e excluded_directories = ""] [-k excluded_items = ""] [-o] [-p number_of_files = 50] [-x allowed_extension = ""] [-f file_to_save = "results.txt"] - finds biggest files
--y <-i directories_to_search> [-e excluded_directories = ""] [-k excluded_items = ""] [-o] [-f file_to_save = "results.txt"] [-delete] - finds empty files
@ -376,7 +376,7 @@ fn print_help() {
-e excluded_directories - list of directories which will be excluded from search(absolute path)
-k excluded_items - list of excluded items which contains * wildcard(may be slow, so use exclude_directories where possible)
-o - this options prevents from recursive check of folders
-s min_size - minimum size of checked files in bytes, assigning bigger value may speed up searching.
-s minimal_file_size - minimum size of checked files in bytes, assigning bigger value may speed up searching.
-p number_of_files - number of showed the biggest files.
-x allowed_extension - list of checked files with provided extensions. There are also helpful macros which allow to easy use a typcal extensions like IMAGE("jpg,kra,gif,png,bmp,tiff,webp,hdr,svg"), TEXT, VIDEO or MUSIC.
-l type_of_search - allows to use fastest method which takes into account only size(SIZE), more accurate which takes into account hash of only first 1MB of file(HASHMB) or fully accurate(but the slowest solution) which check hash of all file(HASH).

View File

@ -92,7 +92,7 @@ pub struct DuplicateFinder {
allowed_extensions: Extensions,
excluded_items: ExcludedItems,
recursive_search: bool,
min_file_size: u64,
minimal_file_size: u64,
check_method: CheckingMethod,
delete_method: DeleteMethod,
}
@ -108,7 +108,7 @@ impl DuplicateFinder {
allowed_extensions: Extensions::new(),
check_method: CheckingMethod::None,
delete_method: DeleteMethod::None,
min_file_size: 1024,
minimal_file_size: 1024,
directories: Directories::new(),
excluded_items: ExcludedItems::new(),
}
@ -149,8 +149,11 @@ impl DuplicateFinder {
self.delete_method = delete_method;
}
pub fn set_min_file_size(&mut self, min_size: u64) {
self.min_file_size = min_size;
pub fn set_minimal_file_size(&mut self, minimal_file_size: u64) {
self.minimal_file_size = match minimal_file_size {
0 => 1,
t => t,
};
}
pub fn set_recursive_search(&mut self, recursive_search: bool) {
@ -266,7 +269,7 @@ impl DuplicateFinder {
}
// Checking files
if metadata.len() >= self.min_file_size && have_valid_extension {
if metadata.len() >= self.minimal_file_size && have_valid_extension {
let current_file_name = "".to_owned() + &current_folder + &entry_data.file_name().into_string().unwrap();
// Checking expressions
@ -492,7 +495,7 @@ impl DebugPrint for DuplicateFinder {
println!("Included directories - {:?}", self.directories.included_directories);
println!("Excluded directories - {:?}", self.directories.excluded_directories);
println!("Recursive search - {}", self.recursive_search.to_string());
println!("Minimum file size - {:?}", self.min_file_size);
println!("Minimum file size - {:?}", self.minimal_file_size);
println!("Checking Method - {:?}", self.check_method);
println!("Delete Method - {:?}", self.delete_method);
println!("-----------------------------------------");

View File

@ -421,7 +421,7 @@ fn main() {
df.set_recursive_search(check_button_recursive.get_active());
df.set_excluded_items(entry_excluded_items.get_text().as_str().to_string());
df.set_allowed_extensions(entry_allowed_extensions.get_text().as_str().to_string());
df.set_min_file_size(match entry_duplicate_minimal_size.get_text().as_str().parse::<u64>() {
df.set_minimal_file_size(match entry_duplicate_minimal_size.get_text().as_str().parse::<u64>() {
Ok(t) => t,
Err(_) => 1024, // By default
});