Removed duplicated entries from included and excluded directories
This commit is contained in:
parent
8cca91d976
commit
d3dee0dd10
|
@ -4,14 +4,15 @@ It is in very early development, so most of the functions aren't added and doesn
|
|||
|
||||
|
||||
## Done
|
||||
- Nothing now
|
||||
- Basic menu
|
||||
|
||||
## TODO
|
||||
- Graphical UI(GTK)
|
||||
- Duplicated file finding
|
||||
- Setting include and exclude directories(Regex support needed)
|
||||
- Setting include and exclude directories
|
||||
- Removing empty folders
|
||||
- Files with debug symbols
|
||||
- Support for showing only duplicates with specific extension, name(Regex support needed)
|
||||
|
||||
## License
|
||||
Czkawka is released under the terms of the GNU Lesser General Public License, version 2.1 or, at your option, any later version, as published by the Free Software Foundation.
|
|
@ -24,18 +24,18 @@ impl DuplicateFinder {
|
|||
included_directories: vec![],
|
||||
}
|
||||
}
|
||||
pub fn clear(&mut self) {
|
||||
self.number_of_checked_files = 0;
|
||||
self.number_of_files_which_has_duplicated_entries = 0;
|
||||
self.number_of_duplicated_files = 0;
|
||||
self.files.clear();
|
||||
self.excluded_directories.clear();
|
||||
self.included_directories.clear();
|
||||
}
|
||||
pub fn find_duplicates(&mut self) {}
|
||||
pub fn save_to_file(&self) {}
|
||||
// pub fn clear(&mut self) {
|
||||
// self.number_of_checked_files = 0;
|
||||
// self.number_of_files_which_has_duplicated_entries = 0;
|
||||
// self.number_of_duplicated_files = 0;
|
||||
// self.files.clear();
|
||||
// self.excluded_directories.clear();
|
||||
// self.included_directories.clear();
|
||||
// }
|
||||
// pub fn find_duplicates(&mut self) {}
|
||||
// pub fn save_to_file(&self) {}
|
||||
|
||||
// Setting include directories, panics when there is not directories available
|
||||
/// Setting include directories, panics when there is not directories available
|
||||
pub fn set_include_directory(&mut self, mut include_directory: String) {
|
||||
if include_directory.len() == 0 {
|
||||
println!("At least one directory must be provided")
|
||||
|
@ -61,7 +61,13 @@ impl DuplicateFinder {
|
|||
println!("Include Directory ERROR: Relative path are not supported.");
|
||||
process::exit(1);
|
||||
}
|
||||
checked_directories.push(directory);
|
||||
|
||||
// directory must end with /, due to possiblity of incorrect assumption, that e.g. /home/rafal is top folder to /home/rafalinho
|
||||
if !directory.ends_with("/") {
|
||||
checked_directories.push(directory + "/");
|
||||
} else {
|
||||
checked_directories.push(directory);
|
||||
}
|
||||
}
|
||||
|
||||
if checked_directories.len() == 0 {
|
||||
|
@ -99,7 +105,13 @@ impl DuplicateFinder {
|
|||
println!("Exclude Directory ERROR: Relative path are not supported.");
|
||||
process::exit(1);
|
||||
}
|
||||
checked_directories.push(directory);
|
||||
|
||||
// directory must end with /, due to possiblity of incorrect assumption, that e.g. /home/rafal is top folder to /home/rafalinho
|
||||
if !directory.ends_with("/") {
|
||||
checked_directories.push(directory + "/");
|
||||
} else {
|
||||
checked_directories.push(directory);
|
||||
}
|
||||
}
|
||||
|
||||
self.excluded_directories = checked_directories;
|
||||
|
@ -120,8 +132,11 @@ impl DuplicateFinder {
|
|||
println!("Included directories - {:?}", self.included_directories);
|
||||
println!("-----------------------------------------");
|
||||
}
|
||||
// Usuwa wykluczone katalogi z wyszukiwania jeśli akurat included i excluded na siebie nachodzą
|
||||
pub fn optimize_checked_directories(&mut self) {
|
||||
/// Remove unused entries when included or excluded overlaps with each other or are duplicated
|
||||
/// ```
|
||||
/// let df : DuplicateFinder = saf
|
||||
/// ```
|
||||
pub fn optimize_directories(&mut self) {
|
||||
let mut optimized_included: Vec<String> = Vec::<String>::new();
|
||||
let mut optimized_excluded: Vec<String> = Vec::<String>::new();
|
||||
// Remove duplicated entries like: "/", "/"
|
||||
|
@ -133,15 +148,45 @@ impl DuplicateFinder {
|
|||
self.included_directories.dedup();
|
||||
|
||||
// Optimize for duplicated included directories - "/", "/home". "/home/Pulpit" to "/"- TODO
|
||||
// for id_1 in &self.excluded_directories {
|
||||
// for id_2 in &self.included_directories {
|
||||
// if id_1 != id_2 && id_1.starts_with(id_2) {}
|
||||
// // optimized_included.push(id.to_string());
|
||||
// }
|
||||
// }
|
||||
// self.included_directories = optimized_included;
|
||||
// optimized_included = Vec::<String>::new();
|
||||
// self.excluded_directories = optimized_excluded;
|
||||
let mut is_inside: bool;
|
||||
for ed_checked in &self.excluded_directories {
|
||||
is_inside = false;
|
||||
for ed_help in &self.excluded_directories {
|
||||
if ed_checked == ed_help {
|
||||
// We checking same element
|
||||
continue;
|
||||
}
|
||||
if ed_checked.starts_with(ed_help) {
|
||||
is_inside = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if is_inside == false {
|
||||
optimized_excluded.push(ed_checked.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
for id_checked in &self.included_directories {
|
||||
is_inside = false;
|
||||
for id_help in &self.included_directories {
|
||||
if id_checked == id_help {
|
||||
// We checking same element
|
||||
continue;
|
||||
}
|
||||
if id_checked.starts_with(id_help) {
|
||||
is_inside = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if is_inside == false {
|
||||
optimized_included.push(id_checked.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
self.included_directories = optimized_included;
|
||||
optimized_included = Vec::<String>::new();
|
||||
self.excluded_directories = optimized_excluded;
|
||||
// optimized_excluded = Vec::<String>::new();
|
||||
|
||||
// Remove include directories which are inside any exclude directory
|
||||
for ed in &self.excluded_directories {
|
||||
|
@ -153,11 +198,16 @@ impl DuplicateFinder {
|
|||
}
|
||||
}
|
||||
self.included_directories = optimized_included;
|
||||
// optimized_included = Vec::<String>::new();
|
||||
|
||||
if self.included_directories.len() == 0 {
|
||||
println!("Optimize Directories ERROR: Excluded directories overlaps all included directories.");
|
||||
process::exit(1);
|
||||
}
|
||||
|
||||
// Not needed, but better is to have sorted everything
|
||||
self.excluded_directories.sort();
|
||||
self.included_directories.sort();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ fn main() {
|
|||
let mut df = duplicate::DuplicateFinder::new();
|
||||
df.set_exclude_directory(arguments[3].to_string());
|
||||
df.set_include_directory(arguments[2].to_string());
|
||||
df.optimize_checked_directories();
|
||||
df.optimize_directories();
|
||||
df.debug_print();
|
||||
}
|
||||
argum => println!("{} argument is not supported, check help for more info.", argum),
|
||||
|
|
Loading…
Reference in a new issue