diff --git a/Cargo.lock b/Cargo.lock index 0f0069ca..84f90ec2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -234,7 +234,7 @@ checksum = "0ae92a5119aa49cdbcf6b9f893fe4e1d98b04ccbf82ee0584ad948a44a734dea" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -420,7 +420,7 @@ checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -455,7 +455,7 @@ checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -482,7 +482,7 @@ dependencies = [ "derive_utils", "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -585,7 +585,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.92", + "syn 2.0.93", "which", ] @@ -763,7 +763,7 @@ checksum = "3fa76293b4f7bb636ab88fd78228235b5248b4d05cc589aed610f954af5d7c7a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -1053,7 +1053,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -1156,7 +1156,7 @@ checksum = "5387f5bbc9e9e6c96436ea125afa12614cebf8ac67f49abc08c1e7a891466c90" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -1690,7 +1690,7 @@ checksum = "30542c1ad912e0e3d22a1935c290e12e8a29d704a420177a31faad4a601a0800" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -1710,7 +1710,7 @@ checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", "unicode-xid", ] @@ -1722,7 +1722,7 @@ checksum = "65f152f4b8559c4da5d574bafc7af85454d706b4c5fe8b530d508cacbb6807ea" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -1771,7 +1771,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -1957,7 +1957,7 @@ checksum = "de0d48a183585823424a4ce1aa132d174a6a81bd540895822eb4c8373a8e49e8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -1968,7 +1968,7 @@ checksum = "2f9ed6b3789237c8a0c1c505af1c7eb2c560df6186f01b098c3a1064ea532f38" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -2309,7 +2309,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -2437,7 +2437,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -2694,7 +2694,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -2709,9 +2709,9 @@ dependencies = [ [[package]] name = "glob" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" +checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" [[package]] name = "globalcache" @@ -2909,7 +2909,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -3222,7 +3222,7 @@ checksum = "f83e6bd30e51baa7adb1c1e04111ac71713ce032ce16c36e62a334f8c45b734e" dependencies = [ "quote", "serde_json", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -3345,7 +3345,7 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.11.1", - "syn 2.0.92", + "syn 2.0.93", "unic-langid", ] @@ -3359,7 +3359,7 @@ dependencies = [ "i18n-config", "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -3500,7 +3500,7 @@ checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -3585,9 +3585,9 @@ dependencies = [ [[package]] name = "image_hasher" -version = "2.0.0" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9481465fe767d92494987319b0b447a5829edf57f09c52bf8639396abaaeaf78" +checksum = "7c191dc6138f559a0177b8413eaf2a37784d8e63c697e247aa3740930f1c9364" dependencies = [ "base64", "image 0.25.5", @@ -3734,7 +3734,7 @@ checksum = "c34819042dc3d3971c46c2190835914dfbe0c3c13f61449b2997f4e9722dfa60" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -4375,7 +4375,7 @@ checksum = "28bd4b9d8a5af74808932492521cdd272019b056f75fcc70056bd2c09fceb550" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -4745,7 +4745,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -4807,7 +4807,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -5289,7 +5289,7 @@ checksum = "3c0f5fad0874fc7abcd4d750e76917eaebbecaa2c20bde22e1dbeeba8beb758c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -5438,7 +5438,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033" dependencies = [ "proc-macro2", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -5478,7 +5478,7 @@ dependencies = [ "proc-macro-error-attr2", "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -5506,7 +5506,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a65f2e60fbf1063868558d69c6beacf412dc755f9fc020f514b7955fc914fe30" dependencies = [ "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -5885,7 +5885,7 @@ dependencies = [ "proc-macro2", "quote", "rust-embed-utils", - "syn 2.0.92", + "syn 2.0.93", "walkdir", ] @@ -6102,7 +6102,7 @@ checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -6136,7 +6136,7 @@ checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -6541,7 +6541,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -6768,9 +6768,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.92" +version = "2.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ae51629bf965c5c098cc9e87908a3df5301051a9e087d6f9bef5c9771ed126" +checksum = "9c786062daee0d6db1132800e623df74274a0a87322d8e183338e01b3d98d058" dependencies = [ "proc-macro2", "quote", @@ -6785,7 +6785,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -6900,7 +6900,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -6911,7 +6911,7 @@ checksum = "7b50fa271071aae2e6ee85f842e2e28ba8cd2c5fb67f11fcb1fd70b276f9e7d4" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -7105,7 +7105,7 @@ checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -7534,7 +7534,7 @@ checksum = "d8502f961cf2f1359fed21a70f67c831ccb3ab9e4c0b4dd3ad40387fbe8875db" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -7603,7 +7603,7 @@ dependencies = [ "log", "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", "wasm-bindgen-shared", ] @@ -7638,7 +7638,7 @@ checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -7908,7 +7908,7 @@ checksum = "f6fc35f58ecd95a9b71c4f2329b911016e6bec66b3f2e6a4aad86bd2e99e2f9b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -7919,7 +7919,7 @@ checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -7930,7 +7930,7 @@ checksum = "08990546bf4edef8f431fa6326e032865f27138718c587dc21bc0265bbcb57cc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -7941,7 +7941,7 @@ checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -8423,7 +8423,7 @@ checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", "synstructure", ] @@ -8510,7 +8510,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", "zvariant_utils 2.1.0", ] @@ -8523,7 +8523,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", "zbus_names 4.1.0", "zvariant 5.1.0", "zvariant_utils 3.0.2", @@ -8570,7 +8570,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -8590,7 +8590,7 @@ checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", "synstructure", ] @@ -8611,7 +8611,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -8633,7 +8633,7 @@ checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -8739,7 +8739,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", "zvariant_utils 2.1.0", ] @@ -8752,7 +8752,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", "zvariant_utils 3.0.2", ] @@ -8764,7 +8764,7 @@ checksum = "c51bcff7cc3dbb5055396bcf774748c3dab426b4b8659046963523cee4808340" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -8777,6 +8777,6 @@ dependencies = [ "quote", "serde", "static_assertions", - "syn 2.0.92", + "syn 2.0.93", "winnow", ] diff --git a/czkawka_cli/Cargo.toml b/czkawka_cli/Cargo.toml index da588d02..726c56cd 100644 --- a/czkawka_cli/Cargo.toml +++ b/czkawka_cli/Cargo.toml @@ -13,7 +13,7 @@ repository = "https://github.com/qarmin/czkawka" clap = { version = "4.5", features = ["derive"] } # For enum types -image_hasher = "2.0" +image_hasher = "3.0" log = "0.4.22" handsome_logger = "0.8" diff --git a/czkawka_core/Cargo.toml b/czkawka_core/Cargo.toml index 7c683bc6..59bbabab 100644 --- a/czkawka_core/Cargo.toml +++ b/czkawka_core/Cargo.toml @@ -19,7 +19,7 @@ crossbeam-channel = "0.5" directories-next = "2.0" # Needed by similar images -image_hasher = "2.0" +image_hasher = "3.0" bk-tree = "0.5" image = { version = "0.25", default-features = false, features = ["bmp", "dds", "exr", "ff", "gif", "hdr", "ico", "jpeg", "png", "pnm", "qoi", "tga", "tiff", "webp"] } hamming-bitwise-fast = "1.0" diff --git a/czkawka_core/benches/hash_calculation_benchmark.rs b/czkawka_core/benches/hash_calculation_benchmark.rs index c979c4b0..87b04699 100644 --- a/czkawka_core/benches/hash_calculation_benchmark.rs +++ b/czkawka_core/benches/hash_calculation_benchmark.rs @@ -1,10 +1,11 @@ -use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use czkawka_core::duplicate::{hash_calculation, DuplicateEntry, HashType}; use std::env::temp_dir; use std::fs::File; use std::io::Write; use std::path::PathBuf; +use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use czkawka_core::duplicate::{hash_calculation, DuplicateEntry, HashType}; + fn setup_test_file(size: u64) -> PathBuf { let mut path = temp_dir(); path.push("test_file"); @@ -25,25 +26,25 @@ fn get_file_entry(size: u64) -> DuplicateEntry { fn benchmark_hash_calculation_vec(c: &mut Criterion) { let file_entry = get_file_entry(FILE_SIZE); - let function_name = format!("hash_calculation_vec_file_{}_buffer_{}", FILE_SIZE, BUFFER_SIZE); + let function_name = format!("hash_calculation_vec_file_{FILE_SIZE}_buffer_{BUFFER_SIZE}"); c.bench_function(&function_name, |b| { b.iter(|| { let mut buffer = vec![0u8; BUFFER_SIZE]; hash_calculation(black_box(&mut buffer), black_box(&file_entry), black_box(HashType::Blake3), black_box(u64::MAX)).expect("Failed to calculate hash"); - }) + }); }); } fn benchmark_hash_calculation_arr(c: &mut Criterion) { let file_entry = get_file_entry(FILE_SIZE); - let function_name = format!("hash_calculation_arr_file_{}_buffer_{}", FILE_SIZE, BUFFER_SIZE); + let function_name = format!("hash_calculation_arr_file_{FILE_SIZE}_buffer_{BUFFER_SIZE}"); c.bench_function(&function_name, |b| { b.iter(|| { let mut buffer = [0u8; BUFFER_SIZE]; hash_calculation(black_box(&mut buffer), black_box(&file_entry), black_box(HashType::Blake3), black_box(u64::MAX)).expect("Failed to calculate hash"); - }) + }); }); } diff --git a/czkawka_core/src/bad_extensions.rs b/czkawka_core/src/bad_extensions.rs index 30782532..cc327b87 100644 --- a/czkawka_core/src/bad_extensions.rs +++ b/czkawka_core/src/bad_extensions.rs @@ -12,7 +12,7 @@ use mime_guess::get_mime_extensions; use rayon::prelude::*; use serde::Serialize; -use crate::common::{check_if_stop_received, prepare_thread_handler_common, send_info_and_wait_for_ending_all_threads}; +use crate::common::{check_if_stop_received, prepare_thread_handler_common, send_info_and_wait_for_ending_all_threads, WorkContinueStatus}; use crate::common_dir_traversal::{DirTraversalBuilder, DirTraversalResult, FileEntry, ToolType}; use crate::common_tool::{CommonData, CommonToolData}; use crate::common_traits::*; @@ -233,11 +233,11 @@ impl BadExtensions { #[fun_time(message = "find_bad_extensions_files", level = "info")] pub fn find_bad_extensions_files(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) { self.prepare_items(); - if !self.check_files(stop_receiver, progress_sender) { + if self.check_files(stop_receiver, progress_sender) == WorkContinueStatus::Stop { self.common_data.stopped_search = true; return; } - if !self.look_for_bad_extensions_files(stop_receiver, progress_sender) { + if self.look_for_bad_extensions_files(stop_receiver, progress_sender) == WorkContinueStatus::Stop { self.common_data.stopped_search = true; return; } @@ -245,7 +245,7 @@ impl BadExtensions { } #[fun_time(message = "check_files", level = "debug")] - fn check_files(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) -> bool { + fn check_files(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) -> WorkContinueStatus { let result = DirTraversalBuilder::new() .common_data(&self.common_data) .group_by(|_fe| ()) @@ -259,17 +259,17 @@ impl BadExtensions { self.files_to_check = grouped_file_entries.into_values().flatten().collect(); self.common_data.text_messages.warnings.extend(warnings); - true + WorkContinueStatus::Continue } - DirTraversalResult::Stopped => false, + DirTraversalResult::Stopped => WorkContinueStatus::Stop, } } #[fun_time(message = "look_for_bad_extensions_files", level = "debug")] - fn look_for_bad_extensions_files(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) -> bool { + fn look_for_bad_extensions_files(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) -> WorkContinueStatus { if self.files_to_check.is_empty() { - return true; + return WorkContinueStatus::Continue; } let (progress_thread_handle, progress_thread_run, atomic_counter, check_was_stopped) = @@ -288,14 +288,14 @@ impl BadExtensions { // Break if stop was clicked if check_was_stopped.load(Ordering::Relaxed) { - return false; + return WorkContinueStatus::Stop; } self.information.number_of_files_with_bad_extension = self.bad_extensions_files.len(); debug!("Found {} files with invalid extension.", self.information.number_of_files_with_bad_extension); - true + WorkContinueStatus::Continue } #[fun_time(message = "verify_extensions", level = "debug")] diff --git a/czkawka_core/src/common_dir_traversal.rs b/czkawka_core/src/common_dir_traversal.rs index 3ebceaae..65365458 100644 --- a/czkawka_core/src/common_dir_traversal.rs +++ b/czkawka_core/src/common_dir_traversal.rs @@ -134,7 +134,7 @@ pub struct DirTraversal<'a, 'b, F> { collect: Collect, } -impl<'a, 'b> Default for DirTraversalBuilder<'a, 'b, ()> { +impl Default for DirTraversalBuilder<'_, '_, ()> { fn default() -> Self { Self::new() } @@ -302,7 +302,7 @@ fn entry_type(file_type: FileType) -> EntryType { } } -impl<'a, 'b, F, T> DirTraversal<'a, 'b, F> +impl DirTraversal<'_, '_, F> where F: Fn(&FileEntry) -> T, T: Ord + PartialOrd, diff --git a/czkawka_core/src/duplicate.rs b/czkawka_core/src/duplicate.rs index 6e06d3fd..4b1d2d28 100644 --- a/czkawka_core/src/duplicate.rs +++ b/czkawka_core/src/duplicate.rs @@ -1,9 +1,3 @@ -use crossbeam_channel::{Receiver, Sender}; -use fun_time::fun_time; -use humansize::{format_size, BINARY}; -use log::debug; -use rayon::prelude::*; -use serde::{Deserialize, Serialize}; use std::cell::RefCell; use std::collections::{BTreeMap, HashMap, HashSet}; use std::fmt::Debug; @@ -16,6 +10,13 @@ use std::os::unix::fs::MetadataExt; use std::path::{Path, PathBuf}; use std::sync::atomic::Ordering; use std::{fs, mem}; + +use crossbeam_channel::{Receiver, Sender}; +use fun_time::fun_time; +use humansize::{format_size, BINARY}; +use log::debug; +use rayon::prelude::*; +use serde::{Deserialize, Serialize}; use xxhash_rust::xxh3::Xxh3; use crate::common::{check_if_stop_received, delete_files_custom, prepare_thread_handler_common, send_info_and_wait_for_ending_all_threads, WorkContinueStatus}; @@ -549,9 +550,9 @@ impl DuplicateFinder { stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>, pre_checked_map: &mut BTreeMap>, - ) -> bool { + ) -> WorkContinueStatus { if self.files_with_identical_size.is_empty() { - return true; + return crate::common::WorkContinueStatus::Continue; } let check_type = self.get_params().hash_type; @@ -562,7 +563,7 @@ impl DuplicateFinder { send_info_and_wait_for_ending_all_threads(&progress_thread_run, progress_thread_handle); if check_if_stop_received(stop_receiver) { - return false; + return crate::common::WorkContinueStatus::Stop; } let (progress_thread_handle, progress_thread_run, atomic_counter, check_was_stopped) = prepare_thread_handler_common( progress_sender, @@ -629,10 +630,10 @@ impl DuplicateFinder { send_info_and_wait_for_ending_all_threads(&progress_thread_run, progress_thread_handle); if check_was_stopped.load(Ordering::Relaxed) || check_if_stop_received(stop_receiver) { - return false; + return crate::common::WorkContinueStatus::Stop; } - true + crate::common::WorkContinueStatus::Continue } fn diff_loaded_and_prechecked_files( @@ -758,9 +759,14 @@ impl DuplicateFinder { } #[fun_time(message = "full_hashing", level = "debug")] - fn full_hashing(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>, pre_checked_map: BTreeMap>) -> bool { + fn full_hashing( + &mut self, + stop_receiver: Option<&Receiver<()>>, + progress_sender: Option<&Sender>, + pre_checked_map: BTreeMap>, + ) -> WorkContinueStatus { if pre_checked_map.is_empty() { - return true; + return crate::common::WorkContinueStatus::Continue; } let (progress_thread_handle, progress_thread_run, _atomic_counter, _check_was_stopped) = @@ -770,7 +776,7 @@ impl DuplicateFinder { send_info_and_wait_for_ending_all_threads(&progress_thread_run, progress_thread_handle); if check_if_stop_received(stop_receiver) { - return false; + return crate::common::WorkContinueStatus::Stop; } let (progress_thread_handle, progress_thread_run, atomic_counter, check_was_stopped) = prepare_thread_handler_common( @@ -835,7 +841,7 @@ impl DuplicateFinder { } } - true + crate::common::WorkContinueStatus::Continue } #[fun_time(message = "hash_reference_folders", level = "debug")] @@ -894,11 +900,11 @@ impl DuplicateFinder { assert_eq!(self.get_params().check_method, CheckingMethod::Hash); let mut pre_checked_map: BTreeMap> = Default::default(); - if !self.prehashing(stop_receiver, progress_sender, &mut pre_checked_map) { + if self.prehashing(stop_receiver, progress_sender, &mut pre_checked_map) == crate::common::WorkContinueStatus::Stop { return crate::common::WorkContinueStatus::Stop; } - if !self.full_hashing(stop_receiver, progress_sender, pre_checked_map) { + if self.full_hashing(stop_receiver, progress_sender, pre_checked_map) == crate::common::WorkContinueStatus::Stop { return crate::common::WorkContinueStatus::Stop; } diff --git a/czkawka_core/src/empty_files.rs b/czkawka_core/src/empty_files.rs index abb7f201..4491d035 100644 --- a/czkawka_core/src/empty_files.rs +++ b/czkawka_core/src/empty_files.rs @@ -5,6 +5,7 @@ use crossbeam_channel::{Receiver, Sender}; use fun_time::fun_time; use log::debug; +use crate::common::WorkContinueStatus; use crate::common_dir_traversal::{DirTraversalBuilder, DirTraversalResult, FileEntry, ToolType}; use crate::common_tool::{CommonData, CommonToolData, DeleteMethod}; use crate::common_traits::*; @@ -42,7 +43,7 @@ impl EmptyFiles { #[fun_time(message = "find_empty_files", level = "info")] pub fn find_empty_files(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) { self.prepare_items(); - if !self.check_files(stop_receiver, progress_sender) { + if self.check_files(stop_receiver, progress_sender) == WorkContinueStatus::Stop { self.common_data.stopped_search = true; return; } @@ -51,7 +52,7 @@ impl EmptyFiles { } #[fun_time(message = "check_files", level = "debug")] - fn check_files(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) -> bool { + fn check_files(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) -> WorkContinueStatus { let result = DirTraversalBuilder::new() .common_data(&self.common_data) .group_by(|_fe| ()) @@ -70,10 +71,10 @@ impl EmptyFiles { debug!("Found {} empty files.", self.information.number_of_empty_files); - true + WorkContinueStatus::Continue } - DirTraversalResult::Stopped => false, + DirTraversalResult::Stopped => WorkContinueStatus::Stop, } } diff --git a/czkawka_core/src/empty_folder.rs b/czkawka_core/src/empty_folder.rs index 3001f835..8d24f5e1 100644 --- a/czkawka_core/src/empty_folder.rs +++ b/czkawka_core/src/empty_folder.rs @@ -10,7 +10,7 @@ use fun_time::fun_time; use log::debug; use rayon::prelude::*; -use crate::common::{check_if_stop_received, prepare_thread_handler_common, send_info_and_wait_for_ending_all_threads}; +use crate::common::{check_if_stop_received, prepare_thread_handler_common, send_info_and_wait_for_ending_all_threads, WorkContinueStatus}; use crate::common_dir_traversal::{common_get_entry_data, common_get_metadata_dir, common_read_dir, get_modified_time, ToolType}; use crate::common_directory::Directories; use crate::common_items::ExcludedItems; @@ -72,7 +72,7 @@ impl EmptyFolder { #[fun_time(message = "find_empty_folders", level = "info")] pub fn find_empty_folders(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) { self.prepare_items(); - if !self.check_for_empty_folders(stop_receiver, progress_sender) { + if self.check_for_empty_folders(stop_receiver, progress_sender) == WorkContinueStatus::Stop { self.common_data.stopped_search = true; return; } @@ -102,7 +102,7 @@ impl EmptyFolder { } #[fun_time(message = "check_for_empty_folders", level = "debug")] - fn check_for_empty_folders(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) -> bool { + fn check_for_empty_folders(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) -> WorkContinueStatus { let mut folders_to_check: Vec = self.common_data.directories.included_directories.clone(); let (progress_thread_handle, progress_thread_run, atomic_counter, _check_was_stopped) = @@ -127,7 +127,7 @@ impl EmptyFolder { while !folders_to_check.is_empty() { if check_if_stop_received(stop_receiver) { send_info_and_wait_for_ending_all_threads(&progress_thread_run, progress_thread_handle); - return false; + return crate::common::WorkContinueStatus::Stop; } let segments: Vec<_> = folders_to_check @@ -219,7 +219,7 @@ impl EmptyFolder { debug!("Found {} empty folders.", self.empty_folder_list.len()); send_info_and_wait_for_ending_all_threads(&progress_thread_run, progress_thread_handle); - true + WorkContinueStatus::Continue } pub(crate) fn set_as_not_empty_folder(folder_entries: &mut HashMap, current_folder: &str) { diff --git a/czkawka_core/src/invalid_symlinks.rs b/czkawka_core/src/invalid_symlinks.rs index 6121bdbf..666576a0 100644 --- a/czkawka_core/src/invalid_symlinks.rs +++ b/czkawka_core/src/invalid_symlinks.rs @@ -7,6 +7,7 @@ use fun_time::fun_time; use log::debug; use serde::{Deserialize, Serialize}; +use crate::common::WorkContinueStatus; use crate::common_dir_traversal::{Collect, DirTraversalBuilder, DirTraversalResult, ErrorType, FileEntry, ToolType}; use crate::common_tool::{CommonData, CommonToolData, DeleteMethod}; use crate::common_traits::*; @@ -74,7 +75,7 @@ impl InvalidSymlinks { #[fun_time(message = "find_invalid_links", level = "info")] pub fn find_invalid_links(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) { self.prepare_items(); - if !self.check_files(stop_receiver, progress_sender) { + if self.check_files(stop_receiver, progress_sender) == WorkContinueStatus::Stop { self.common_data.stopped_search = true; return; } @@ -83,7 +84,7 @@ impl InvalidSymlinks { } #[fun_time(message = "check_files", level = "debug")] - fn check_files(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) -> bool { + fn check_files(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) -> WorkContinueStatus { let result = DirTraversalBuilder::new() .common_data(&self.common_data) .group_by(|_fe| ()) @@ -106,9 +107,9 @@ impl InvalidSymlinks { self.information.number_of_invalid_symlinks = self.invalid_symlinks.len(); self.common_data.text_messages.warnings.extend(warnings); debug!("Found {} invalid symlinks.", self.information.number_of_invalid_symlinks); - true + crate::common::WorkContinueStatus::Continue } - DirTraversalResult::Stopped => false, + DirTraversalResult::Stopped => crate::common::WorkContinueStatus::Stop, } } diff --git a/czkawka_core/src/same_music.rs b/czkawka_core/src/same_music.rs index 96defdfe..a734ddfe 100644 --- a/czkawka_core/src/same_music.rs +++ b/czkawka_core/src/same_music.rs @@ -26,7 +26,7 @@ use symphonia::core::probe::Hint; use crate::common::{ check_if_stop_received, create_crash_message, delete_files_custom, filter_reference_folders_generic, prepare_thread_handler_common, send_info_and_wait_for_ending_all_threads, - AUDIO_FILES_EXTENSIONS, + WorkContinueStatus, AUDIO_FILES_EXTENSIONS, }; use crate::common_cache::{extract_loaded_cache, get_similar_music_cache_file, load_cache_from_file_generalized_by_path, save_cache_to_file_generalized}; use crate::common_dir_traversal::{CheckingMethod, DirTraversalBuilder, DirTraversalResult, FileEntry, ToolType}; @@ -165,31 +165,31 @@ impl SameMusic { pub fn find_same_music(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) { self.prepare_items(); self.common_data.use_reference_folders = !self.common_data.directories.reference_directories.is_empty(); - if !self.check_files(stop_receiver, progress_sender) { + if self.check_files(stop_receiver, progress_sender) == crate::common::WorkContinueStatus::Stop { self.common_data.stopped_search = true; return; } match self.params.check_type { CheckingMethod::AudioTags => { - if !self.read_tags(stop_receiver, progress_sender) { + if self.read_tags(stop_receiver, progress_sender) == crate::common::WorkContinueStatus::Stop { self.common_data.stopped_search = true; return; } - if !self.check_for_duplicate_tags(stop_receiver, progress_sender) { + if self.check_for_duplicate_tags(stop_receiver, progress_sender) == crate::common::WorkContinueStatus::Stop { self.common_data.stopped_search = true; return; } } CheckingMethod::AudioContent => { - if !self.read_tags(stop_receiver, progress_sender) { + if self.read_tags(stop_receiver, progress_sender) == crate::common::WorkContinueStatus::Stop { self.common_data.stopped_search = true; return; } - if !self.calculate_fingerprint(stop_receiver, progress_sender) { + if self.calculate_fingerprint(stop_receiver, progress_sender) == crate::common::WorkContinueStatus::Stop { self.common_data.stopped_search = true; return; } - if !self.check_for_duplicate_fingerprints(stop_receiver, progress_sender) { + if self.check_for_duplicate_fingerprints(stop_receiver, progress_sender) == crate::common::WorkContinueStatus::Stop { self.common_data.stopped_search = true; return; } @@ -201,10 +201,10 @@ impl SameMusic { } #[fun_time(message = "check_files", level = "debug")] - fn check_files(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) -> bool { + fn check_files(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) -> WorkContinueStatus { self.common_data.extensions.set_and_validate_allowed_extensions(AUDIO_FILES_EXTENSIONS); if !self.common_data.extensions.set_any_extensions() { - return true; + return crate::common::WorkContinueStatus::Continue; } let result = DirTraversalBuilder::new() @@ -225,10 +225,10 @@ impl SameMusic { .collect(); self.common_data.text_messages.warnings.extend(warnings); debug!("check_files - Found {} music files.", self.music_to_check.len()); - true + crate::common::WorkContinueStatus::Continue } - DirTraversalResult::Stopped => false, + DirTraversalResult::Stopped => crate::common::WorkContinueStatus::Stop, } } @@ -283,9 +283,9 @@ impl SameMusic { } #[fun_time(message = "calculate_fingerprint", level = "debug")] - fn calculate_fingerprint(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) -> bool { + fn calculate_fingerprint(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) -> WorkContinueStatus { if self.music_entries.is_empty() { - return true; + return crate::common::WorkContinueStatus::Continue; } // We only calculate fingerprints, for files with similar titles @@ -310,7 +310,7 @@ impl SameMusic { send_info_and_wait_for_ending_all_threads(&progress_thread_run, progress_thread_handle); if check_if_stop_received(stop_receiver) { - return false; + return crate::common::WorkContinueStatus::Stop; } let (progress_thread_handle, progress_thread_run, atomic_counter, check_was_stopped) = prepare_thread_handler_common( @@ -357,15 +357,15 @@ impl SameMusic { // Break if stop was clicked after saving to cache send_info_and_wait_for_ending_all_threads(&progress_thread_run, progress_thread_handle); if check_was_stopped.load(Ordering::Relaxed) || check_if_stop_received(stop_receiver) { - return false; + return crate::common::WorkContinueStatus::Stop; } - true + crate::common::WorkContinueStatus::Continue } #[fun_time(message = "read_tags", level = "debug")] - fn read_tags(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) -> bool { + fn read_tags(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) -> WorkContinueStatus { if self.music_to_check.is_empty() { - return true; + return crate::common::WorkContinueStatus::Continue; } let (progress_thread_handle, progress_thread_run, _atomic_counter, _check_was_stopped) = @@ -375,7 +375,7 @@ impl SameMusic { send_info_and_wait_for_ending_all_threads(&progress_thread_run, progress_thread_handle); if check_if_stop_received(stop_receiver) { - return false; + return crate::common::WorkContinueStatus::Stop; } let (progress_thread_handle, progress_thread_run, atomic_counter, check_was_stopped) = @@ -416,16 +416,16 @@ impl SameMusic { // Break if stop was clicked after saving to cache send_info_and_wait_for_ending_all_threads(&progress_thread_run, progress_thread_handle); if check_was_stopped.load(Ordering::Relaxed) { - return false; + return crate::common::WorkContinueStatus::Stop; } - true + crate::common::WorkContinueStatus::Continue } #[fun_time(message = "check_for_duplicate_tags", level = "debug")] - fn check_for_duplicate_tags(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) -> bool { + fn check_for_duplicate_tags(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) -> WorkContinueStatus { if self.music_entries.is_empty() { - return true; + return crate::common::WorkContinueStatus::Continue; } let (progress_thread_handle, progress_thread_run, atomic_counter, _check_was_stopped) = prepare_thread_handler_common(progress_sender, CurrentStage::SameMusicComparingTags, self.music_entries.len(), self.get_test_type()); @@ -436,7 +436,7 @@ impl SameMusic { if (self.params.music_similarity & MusicSimilarity::TRACK_TITLE) == MusicSimilarity::TRACK_TITLE { if check_if_stop_received(stop_receiver) { send_info_and_wait_for_ending_all_threads(&progress_thread_run, progress_thread_handle); - return false; + return crate::common::WorkContinueStatus::Stop; } old_duplicates = self.check_music_item(old_duplicates, &atomic_counter, |fe| &fe.track_title, self.params.approximate_comparison); @@ -444,7 +444,7 @@ impl SameMusic { if (self.params.music_similarity & MusicSimilarity::TRACK_ARTIST) == MusicSimilarity::TRACK_ARTIST { if check_if_stop_received(stop_receiver) { send_info_and_wait_for_ending_all_threads(&progress_thread_run, progress_thread_handle); - return false; + return crate::common::WorkContinueStatus::Stop; } old_duplicates = self.check_music_item(old_duplicates, &atomic_counter, |fe| &fe.track_artist, self.params.approximate_comparison); @@ -452,7 +452,7 @@ impl SameMusic { if (self.params.music_similarity & MusicSimilarity::YEAR) == MusicSimilarity::YEAR { if check_if_stop_received(stop_receiver) { send_info_and_wait_for_ending_all_threads(&progress_thread_run, progress_thread_handle); - return false; + return crate::common::WorkContinueStatus::Stop; } old_duplicates = self.check_music_item(old_duplicates, &atomic_counter, |fe| &fe.year, false); @@ -460,7 +460,7 @@ impl SameMusic { if (self.params.music_similarity & MusicSimilarity::LENGTH) == MusicSimilarity::LENGTH { if check_if_stop_received(stop_receiver) { send_info_and_wait_for_ending_all_threads(&progress_thread_run, progress_thread_handle); - return false; + return crate::common::WorkContinueStatus::Stop; } old_duplicates = self.check_music_item(old_duplicates, &atomic_counter, |fe| &fe.length, false); @@ -468,7 +468,7 @@ impl SameMusic { if (self.params.music_similarity & MusicSimilarity::GENRE) == MusicSimilarity::GENRE { if check_if_stop_received(stop_receiver) { send_info_and_wait_for_ending_all_threads(&progress_thread_run, progress_thread_handle); - return false; + return crate::common::WorkContinueStatus::Stop; } old_duplicates = self.check_music_item(old_duplicates, &atomic_counter, |fe| &fe.genre, false); @@ -476,7 +476,7 @@ impl SameMusic { if (self.params.music_similarity & MusicSimilarity::BITRATE) == MusicSimilarity::BITRATE { if check_if_stop_received(stop_receiver) { send_info_and_wait_for_ending_all_threads(&progress_thread_run, progress_thread_handle); - return false; + return crate::common::WorkContinueStatus::Stop; } let old_duplicates_len = old_duplicates.len(); for vec_file_entry in old_duplicates { @@ -522,7 +522,7 @@ impl SameMusic { // Clear unused data self.music_entries.clear(); - true + crate::common::WorkContinueStatus::Continue } fn split_fingerprints_to_base_and_files_to_compare(&self, music_data: Vec) -> (Vec, Vec) { @@ -645,9 +645,9 @@ impl SameMusic { } #[fun_time(message = "check_for_duplicate_fingerprints", level = "debug")] - fn check_for_duplicate_fingerprints(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) -> bool { + fn check_for_duplicate_fingerprints(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) -> WorkContinueStatus { if self.music_entries.is_empty() { - return true; + return crate::common::WorkContinueStatus::Continue; } let grouped_files_to_check = self.split_fingerprints_to_check(); @@ -661,7 +661,7 @@ impl SameMusic { let GroupedFilesToCheck { base_files, files_to_compare } = group; let Some(temp_music_entries) = self.compare_fingerprints(stop_receiver, &atomic_counter, base_files, &files_to_compare) else { send_info_and_wait_for_ending_all_threads(&progress_thread_run, progress_thread_handle); - return false; + return crate::common::WorkContinueStatus::Stop; }; duplicated_music_entries.extend(temp_music_entries); } @@ -689,7 +689,7 @@ impl SameMusic { // Clear unused data self.music_entries.clear(); - true + crate::common::WorkContinueStatus::Continue } #[fun_time(message = "check_music_item", level = "debug")] diff --git a/czkawka_core/src/similar_images.rs b/czkawka_core/src/similar_images.rs index 3ef8611f..04975225 100644 --- a/czkawka_core/src/similar_images.rs +++ b/czkawka_core/src/similar_images.rs @@ -17,8 +17,8 @@ use rayon::prelude::*; use serde::{Deserialize, Serialize}; use crate::common::{ - check_if_stop_received, delete_files_custom, prepare_thread_handler_common, send_info_and_wait_for_ending_all_threads, HEIC_EXTENSIONS, IMAGE_RS_SIMILAR_IMAGES_EXTENSIONS, - JXL_IMAGE_EXTENSIONS, RAW_IMAGE_EXTENSIONS, + check_if_stop_received, delete_files_custom, prepare_thread_handler_common, send_info_and_wait_for_ending_all_threads, WorkContinueStatus, HEIC_EXTENSIONS, + IMAGE_RS_SIMILAR_IMAGES_EXTENSIONS, JXL_IMAGE_EXTENSIONS, RAW_IMAGE_EXTENSIONS, }; use crate::common_cache::{extract_loaded_cache, get_similar_images_cache_file, load_cache_from_file_generalized_by_path, save_cache_to_file_generalized}; use crate::common_dir_traversal::{inode, take_1_per_inode, DirTraversalBuilder, DirTraversalResult, FileEntry, ToolType}; @@ -160,15 +160,15 @@ impl SimilarImages { pub fn find_similar_images(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) { self.prepare_items(); self.common_data.use_reference_folders = !self.common_data.directories.reference_directories.is_empty(); - if !self.check_for_similar_images(stop_receiver, progress_sender) { + if self.check_for_similar_images(stop_receiver, progress_sender) == WorkContinueStatus::Stop { self.common_data.stopped_search = true; return; } - if !self.hash_images(stop_receiver, progress_sender) { + if self.hash_images(stop_receiver, progress_sender) == WorkContinueStatus::Stop { self.common_data.stopped_search = true; return; } - if !self.find_similar_hashes(stop_receiver, progress_sender) { + if self.find_similar_hashes(stop_receiver, progress_sender) == WorkContinueStatus::Stop { self.common_data.stopped_search = true; return; } @@ -177,7 +177,7 @@ impl SimilarImages { } #[fun_time(message = "check_for_similar_images", level = "debug")] - fn check_for_similar_images(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) -> bool { + fn check_for_similar_images(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) -> WorkContinueStatus { if cfg!(feature = "heif") { self.common_data .extensions @@ -189,7 +189,7 @@ impl SimilarImages { } if !self.common_data.extensions.set_any_extensions() { - return true; + return crate::common::WorkContinueStatus::Continue; } let result = DirTraversalBuilder::new() @@ -214,10 +214,10 @@ impl SimilarImages { .collect(); self.common_data.text_messages.warnings.extend(warnings); debug!("check_files - Found {} image files.", self.images_to_check.len()); - true + crate::common::WorkContinueStatus::Continue } - DirTraversalResult::Stopped => false, + DirTraversalResult::Stopped => crate::common::WorkContinueStatus::Stop, } } @@ -266,9 +266,9 @@ impl SimilarImages { // - Join all hashes and save it to file #[fun_time(message = "hash_images", level = "debug")] - fn hash_images(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) -> bool { + fn hash_images(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) -> WorkContinueStatus { if self.images_to_check.is_empty() { - return true; + return crate::common::WorkContinueStatus::Continue; } let (loaded_hash_map, records_already_cached, non_cached_files_to_check) = self.hash_images_load_cache(); @@ -323,10 +323,10 @@ impl SimilarImages { // Break if stop was clicked after saving to cache if check_was_stopped.load(Ordering::Relaxed) { - return false; + return crate::common::WorkContinueStatus::Stop; } - true + crate::common::WorkContinueStatus::Continue } #[fun_time(message = "save_to_cache", level = "debug")] @@ -448,7 +448,7 @@ impl SimilarImages { progress_sender: Option<&Sender>, stop_receiver: Option<&Receiver<()>>, tolerance: u32, - ) -> bool { + ) -> WorkContinueStatus { // Don't use hashes with multiple images in bktree, because they will always be master of group and cannot be find by other hashes let (base_hashes, hashes_with_multiple_images) = self.split_hashes(all_hashed_images); @@ -503,7 +503,7 @@ impl SimilarImages { if check_was_stopped.load(Ordering::Relaxed) { send_info_and_wait_for_ending_all_threads(&progress_thread_run, progress_thread_handle); - return false; + return crate::common::WorkContinueStatus::Stop; } self.connect_results(partial_results, &mut hashes_parents, &mut hashes_similarity, &hashes_with_multiple_images); @@ -514,7 +514,7 @@ impl SimilarImages { debug_check_for_duplicated_things(self.common_data.use_reference_folders, &hashes_parents, &hashes_similarity, all_hashed_images, "LATTER"); self.collect_hash_compare_result(hashes_parents, &hashes_with_multiple_images, all_hashed_images, collected_similar_images, hashes_similarity); - true + crate::common::WorkContinueStatus::Continue } #[fun_time(message = "connect_results", level = "debug")] @@ -582,9 +582,9 @@ impl SimilarImages { } #[fun_time(message = "find_similar_hashes", level = "debug")] - fn find_similar_hashes(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) -> bool { + fn find_similar_hashes(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) -> WorkContinueStatus { if self.image_hashes.is_empty() { - return true; + return crate::common::WorkContinueStatus::Continue; } let tolerance = self.get_params().similarity; @@ -601,8 +601,10 @@ impl SimilarImages { collected_similar_images.insert(hash, vec_file_entry); } } - } else if !self.compare_hashes_with_non_zero_tolerance(&all_hashed_images, &mut collected_similar_images, progress_sender, stop_receiver, tolerance) { - return false; + } else if self.compare_hashes_with_non_zero_tolerance(&all_hashed_images, &mut collected_similar_images, progress_sender, stop_receiver, tolerance) + == crate::common::WorkContinueStatus::Stop + { + return crate::common::WorkContinueStatus::Stop; } self.verify_duplicated_items(&collected_similar_images); @@ -631,7 +633,7 @@ impl SimilarImages { self.images_to_check = Default::default(); self.bktree = BKTree::new(Hamming); - true + crate::common::WorkContinueStatus::Continue } #[fun_time(message = "exclude_items_with_same_size", level = "debug")] diff --git a/czkawka_core/src/similar_videos.rs b/czkawka_core/src/similar_videos.rs index 6f242a8f..a8207fac 100644 --- a/czkawka_core/src/similar_videos.rs +++ b/czkawka_core/src/similar_videos.rs @@ -12,7 +12,9 @@ use rayon::prelude::*; use serde::{Deserialize, Serialize}; use vid_dup_finder_lib::{ffmpeg_builder, VideoHash}; -use crate::common::{check_if_stop_received, delete_files_custom, prepare_thread_handler_common, send_info_and_wait_for_ending_all_threads, VIDEO_FILES_EXTENSIONS}; +use crate::common::{ + check_if_stop_received, delete_files_custom, prepare_thread_handler_common, send_info_and_wait_for_ending_all_threads, WorkContinueStatus, VIDEO_FILES_EXTENSIONS, +}; use crate::common_cache::{extract_loaded_cache, get_similar_videos_cache_file, load_cache_from_file_generalized_by_path, save_cache_to_file_generalized}; use crate::common_dir_traversal::{inode, take_1_per_inode, DirTraversalBuilder, DirTraversalResult, FileEntry, ToolType}; use crate::common_tool::{CommonData, CommonToolData, DeleteMethod}; @@ -125,11 +127,11 @@ impl SimilarVideos { } else { self.prepare_items(); self.common_data.use_reference_folders = !self.common_data.directories.reference_directories.is_empty(); - if !self.check_for_similar_videos(stop_receiver, progress_sender) { + if self.check_for_similar_videos(stop_receiver, progress_sender) == crate::common::WorkContinueStatus::Stop { self.common_data.stopped_search = true; return; } - if !self.sort_videos(stop_receiver, progress_sender) { + if self.sort_videos(stop_receiver, progress_sender) == crate::common::WorkContinueStatus::Stop { self.common_data.stopped_search = true; return; } @@ -139,10 +141,10 @@ impl SimilarVideos { } #[fun_time(message = "check_for_similar_videos", level = "debug")] - fn check_for_similar_videos(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) -> bool { + fn check_for_similar_videos(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) -> WorkContinueStatus { self.common_data.extensions.set_and_validate_allowed_extensions(VIDEO_FILES_EXTENSIONS); if !self.common_data.extensions.set_any_extensions() { - return true; + return crate::common::WorkContinueStatus::Continue; } let result = DirTraversalBuilder::new() @@ -162,10 +164,10 @@ impl SimilarVideos { .collect(); self.common_data.text_messages.warnings.extend(warnings); debug!("check_files - Found {} video files.", self.videos_to_check.len()); - true + crate::common::WorkContinueStatus::Continue } - DirTraversalResult::Stopped => false, + DirTraversalResult::Stopped => crate::common::WorkContinueStatus::Stop, } } @@ -195,9 +197,9 @@ impl SimilarVideos { } #[fun_time(message = "sort_videos", level = "debug")] - fn sort_videos(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) -> bool { + fn sort_videos(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) -> WorkContinueStatus { if self.videos_to_check.is_empty() { - return true; + return crate::common::WorkContinueStatus::Continue; } let (loaded_hash_map, records_already_cached, non_cached_files_to_check) = self.load_cache_at_start(); @@ -257,7 +259,7 @@ impl SimilarVideos { // Break if stop was clicked after saving to cache if check_was_stopped.load(Ordering::Relaxed) { - return false; + return crate::common::WorkContinueStatus::Stop; } self.match_groups_of_videos(vector_of_hashes, &hashmap_with_file_entries); @@ -279,7 +281,7 @@ impl SimilarVideos { self.videos_hashes = Default::default(); self.videos_to_check = Default::default(); - true + crate::common::WorkContinueStatus::Continue } #[fun_time(message = "save_cache", level = "debug")] diff --git a/czkawka_core/src/temporary.rs b/czkawka_core/src/temporary.rs index e4c5ab3f..1bc60253 100644 --- a/czkawka_core/src/temporary.rs +++ b/czkawka_core/src/temporary.rs @@ -10,7 +10,7 @@ use fun_time::fun_time; use rayon::prelude::*; use serde::Serialize; -use crate::common::{check_folder_children, check_if_stop_received, prepare_thread_handler_common, send_info_and_wait_for_ending_all_threads}; +use crate::common::{check_folder_children, check_if_stop_received, prepare_thread_handler_common, send_info_and_wait_for_ending_all_threads, WorkContinueStatus}; use crate::common_dir_traversal::{common_read_dir, get_modified_time, ToolType}; use crate::common_tool::{CommonData, CommonToolData, DeleteMethod}; use crate::common_traits::*; @@ -70,7 +70,7 @@ impl Temporary { #[fun_time(message = "find_temporary_files", level = "info")] pub fn find_temporary_files(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) { self.prepare_items(); - if !self.check_files(stop_receiver, progress_sender) { + if self.check_files(stop_receiver, progress_sender) == crate::common::WorkContinueStatus::Stop { self.common_data.stopped_search = true; return; } @@ -79,7 +79,7 @@ impl Temporary { } #[fun_time(message = "check_files", level = "debug")] - fn check_files(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) -> bool { + fn check_files(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&Sender>) -> WorkContinueStatus { let mut folders_to_check: Vec = self.common_data.directories.included_directories.clone(); let (progress_thread_handle, progress_thread_run, atomic_counter, _check_was_stopped) = @@ -88,7 +88,7 @@ impl Temporary { while !folders_to_check.is_empty() { if check_if_stop_received(stop_receiver) { send_info_and_wait_for_ending_all_threads(&progress_thread_run, progress_thread_handle); - return false; + return crate::common::WorkContinueStatus::Stop; } let segments: Vec<_> = folders_to_check @@ -146,7 +146,7 @@ impl Temporary { send_info_and_wait_for_ending_all_threads(&progress_thread_run, progress_thread_handle); self.information.number_of_temporary_files = self.temporary_files.len(); - true + crate::common::WorkContinueStatus::Continue } pub fn get_file_entry(&self, atomic_counter: &Arc, entry_data: &DirEntry, warnings: &mut Vec) -> Option { atomic_counter.fetch_add(1, Ordering::Relaxed); diff --git a/czkawka_gui/Cargo.toml b/czkawka_gui/Cargo.toml index 3066cacf..2af748b6 100644 --- a/czkawka_gui/Cargo.toml +++ b/czkawka_gui/Cargo.toml @@ -33,7 +33,7 @@ image = "0.25" regex = "1.11" # To get image_hasher types -image_hasher = "2.0" +image_hasher = "3.0" # Move files to trash trash = "5.1" diff --git a/krokiet/Cargo.toml b/krokiet/Cargo.toml index 5408c66e..43310710 100644 --- a/krokiet/Cargo.toml +++ b/krokiet/Cargo.toml @@ -25,7 +25,7 @@ serde_json = "1.0" humansize = "2.1" image = "0.25" directories-next = "2.0" -image_hasher = "2.0" +image_hasher = "3.0" rayon = "1.10" fs_extra = "1.3" # TODO replace with less buggy library trash = "5.1"