From b89d7ea00be3ef56962ff87aafc0ee13f0540d5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Mikrut?= Date: Tue, 2 May 2023 17:03:10 +0200 Subject: [PATCH] Probably last part --- czkawka_core/src/same_music.rs | 2 +- czkawka_core/src/similar_images.rs | 67 ++++++++++++++++-------------- 2 files changed, 37 insertions(+), 32 deletions(-) diff --git a/czkawka_core/src/same_music.rs b/czkawka_core/src/same_music.rs index 12005f1..8fcf75d 100644 --- a/czkawka_core/src/same_music.rs +++ b/czkawka_core/src/same_music.rs @@ -144,7 +144,7 @@ impl SameMusic { use_reference_folders: false, duplicated_music_entries_referenced: vec![], save_also_as_json: false, - check_type: AudioCheckMethod::Content, + check_type: AudioCheckMethod::Tags, } } diff --git a/czkawka_core/src/similar_images.rs b/czkawka_core/src/similar_images.rs index b4e7c6f..0d0b34f 100644 --- a/czkawka_core/src/similar_images.rs +++ b/czkawka_core/src/similar_images.rs @@ -660,10 +660,7 @@ impl SimilarImages { } } - #[cfg(debug_assertions)] - if !self.use_reference_folders { - debug_check_for_duplicated_things(&hashes_parents, &hashes_similarity, all_hashed_images, "BEFORE"); - } + debug_check_for_duplicated_things(self.use_reference_folders, &hashes_parents, &hashes_similarity, all_hashed_images, "BEFORE"); Some((hashes_parents, hashes_similarity)) } @@ -827,10 +824,7 @@ impl SimilarImages { } } - #[cfg(debug_assertions)] - if !self.use_reference_folders { - debug_check_for_duplicated_things(&hashes_parents, &hashes_similarity, all_hashed_images, "LATTER"); - } + debug_check_for_duplicated_things(self.use_reference_folders, &hashes_parents, &hashes_similarity, all_hashed_images, "LATTER"); // Just simple check if all original hashes with multiple entries are available in end results let original_hashes_at_start = hashes_with_multiple_images.len(); @@ -982,35 +976,36 @@ impl SimilarImages { } #[allow(dead_code)] + #[allow(unreachable_code)] + #[allow(unused_variables)] pub fn verify_duplicated_items(&self, collected_similar_images: &HashMap>) { + #[cfg(not(debug_assertions))] + return; // Validating if group contains duplicated results - #[cfg(debug_assertions)] - { - let mut result_hashset: HashSet = Default::default(); - let mut found = false; - for vec_file_entry in collected_similar_images.values() { - if vec_file_entry.is_empty() { - println!("Empty group"); + let mut result_hashset: HashSet = Default::default(); + let mut found = false; + for vec_file_entry in collected_similar_images.values() { + if vec_file_entry.is_empty() { + println!("Empty group"); + found = true; + continue; + } + if vec_file_entry.len() == 1 { + println!("Single Element {vec_file_entry:?}"); + found = true; + continue; + } + for file_entry in vec_file_entry { + let st = file_entry.path.to_string_lossy().to_string(); + if result_hashset.contains(&st) { found = true; - continue; - } - if vec_file_entry.len() == 1 { - println!("Single Element {vec_file_entry:?}"); - found = true; - continue; - } - for file_entry in vec_file_entry { - let st = file_entry.path.to_string_lossy().to_string(); - if result_hashset.contains(&st) { - found = true; - println!("Duplicated Element {st}"); - } else { - result_hashset.insert(st); - } + println!("Duplicated Element {st}"); + } else { + result_hashset.insert(st); } } - assert!(!found, "Found Invalid entries, verify errors before"); // TODO crashes with empty result with reference folder, verify why } + assert!(!found, "Found Invalid entries, verify errors before"); // TODO crashes with empty result with reference folder, verify why } /// Set included dir which needs to be relative, exists etc. @@ -1391,15 +1386,25 @@ pub fn test_image_conversion_speed() { } #[allow(dead_code)] +#[allow(unreachable_code)] +#[allow(unused_variables)] // Function to validate if after first check there are any duplicated entries // E.g. /a.jpg is used also as master and similar image which is forbidden, because may // cause accidentally delete more pictures that user wanted fn debug_check_for_duplicated_things( + use_reference_folders: bool, hashes_parents: &HashMap, hashes_similarity: &HashMap, all_hashed_images: &HashMap>, numm: &str, ) { + #[cfg(not(debug_assertions))] + return; + + if use_reference_folders { + return; + } + let mut found_broken_thing = false; let mut hashmap_hashes: HashSet<_> = Default::default(); let mut hashmap_names: HashSet<_> = Default::default();