Skip to content

Commit b15c7a0

Browse files
authored
Tests, small image similarity improvements, cli dry runs (#1685)
1 parent c5dbbc1 commit b15c7a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+4128
-573
lines changed

Cargo.lock

Lines changed: 93 additions & 103 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Changelog.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99
- Delayed removing destination file while symlinking, to avoid data loss in case of failure - [#1672](https://github.com/qarmin/czkawka/pull/1672)
1010
- Fix invalid canonicalization of paths on windows - [#1604](https://github.com/qarmin/czkawka/pull/1604/files)
1111
- Comparison results are now deterministic - [#1654](https://github.com/qarmin/czkawka/pull/1654)
12-
- Reading built-in jpeg inside raw images, if available - [#1655](https://github.com/qarmin/czkawka/pull/1655)
12+
- Reading built-in jpeg inside raw images, if available(currently disabled due - https://github.com/dnglab/dnglab/issues/638) - [#1655](https://github.com/qarmin/czkawka/pull/1655)
1313
- Fixed silent panics, when logger cannot log to terminal - [1658](https://github.com/qarmin/czkawka/pull/1658)
1414
- Commit hash is added to logs - [#1672](https://github.com/qarmin/czkawka/pull/1672)
15+
- Improved and fixed logic which groups similar images by its similarity - [#1685](https://github.com/qarmin/czkawka/pull/1685)
16+
- Added counting scan time - [#1674](https://github.com/qarmin/czkawka/pull/1674), [#1685](https://github.com/qarmin/czkawka/pull/1685)
1517

1618
### CLI
1719
- Using colors by default in terminal output(can be disabled by feature flag) - [#1672](https://github.com/qarmin/czkawka/pull/1672)
1820
- Fixed regression, where results were not printed by default to terminal - [#1672](https://github.com/qarmin/czkawka/pull/1672)
21+
- Added dry_run and move_to_trash options to all tools - [#1685](https://github.com/qarmin/czkawka/pull/1685)
1922

2023
### GTK GUI
2124
- Sort button is restored and crashes when sorting are fixed(probably) - [#1623](https://github.com/qarmin/czkawka/pull/1623)

czkawka_cli/src/commands.rs

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,14 @@ pub struct DuplicatesArgs {
170170
pub case_sensitive_name_comparison: CaseSensitiveNameComparison,
171171
#[clap(flatten)]
172172
pub allow_hard_links: AllowHardLinks,
173-
#[clap(flatten)]
174-
pub dry_run: DryRun,
175173
}
176174

177175
#[derive(Debug, clap::Args)]
178176
pub struct EmptyFoldersArgs {
179177
#[clap(flatten)]
180178
pub common_cli_items: CommonCliItems,
181-
#[clap(short = 'D', long, help = "Delete found folders")]
182-
pub delete_folders: bool,
179+
#[clap(flatten)]
180+
pub delete_method: SDMethod,
183181
}
184182

185183
#[derive(Debug, clap::Args)]
@@ -188,8 +186,8 @@ pub struct BiggestFilesArgs {
188186
pub common_cli_items: CommonCliItems,
189187
#[clap(short, long, default_value = "50", help = "Number of files to be shown")]
190188
pub number_of_files: usize,
191-
#[clap(short = 'D', long, help = "Delete found files")]
192-
pub delete_files: bool,
189+
#[clap(flatten)]
190+
pub delete_method: SDMethod,
193191
#[clap(short = 'J', long, help = "Finds the smallest files instead the biggest")]
194192
pub smallest_mode: bool,
195193
}
@@ -198,16 +196,16 @@ pub struct BiggestFilesArgs {
198196
pub struct EmptyFilesArgs {
199197
#[clap(flatten)]
200198
pub common_cli_items: CommonCliItems,
201-
#[clap(short = 'D', long, help = "Delete found files")]
202-
pub delete_files: bool,
199+
#[clap(flatten)]
200+
pub delete_method: SDMethod,
203201
}
204202

205203
#[derive(Debug, clap::Args)]
206204
pub struct TemporaryArgs {
207205
#[clap(flatten)]
208206
pub common_cli_items: CommonCliItems,
209-
#[clap(short = 'D', long, help = "Delete found files")]
210-
pub delete_files: bool,
207+
#[clap(flatten)]
208+
pub delete_method: SDMethod,
211209
}
212210

213211
#[derive(Debug, clap::Args)]
@@ -248,8 +246,6 @@ pub struct SimilarImagesArgs {
248246
#[clap(flatten)]
249247
pub allow_hard_links: AllowHardLinks,
250248
#[clap(flatten)]
251-
pub dry_run: DryRun,
252-
#[clap(flatten)]
253249
pub ignore_same_size: IgnoreSameSize,
254250
#[clap(
255251
short = 'g',
@@ -285,8 +281,6 @@ pub struct SameMusicArgs {
285281
pub reference_directories: ReferenceDirectories,
286282
#[clap(flatten)]
287283
pub delete_method: DMethod,
288-
#[clap(flatten)]
289-
pub dry_run: DryRun,
290284
#[clap(short, long, help = "Approximate comparison of music tags.")]
291285
pub approximate_comparison: bool,
292286
#[clap(short, long, help = "Compare fingerprints only with similar titles.")]
@@ -380,16 +374,16 @@ fn parse_minimum_segment_duration(src: &str) -> Result<f32, String> {
380374
pub struct InvalidSymlinksArgs {
381375
#[clap(flatten)]
382376
pub common_cli_items: CommonCliItems,
383-
#[clap(short = 'D', long, help = "Delete found files")]
384-
pub delete_files: bool,
377+
#[clap(flatten)]
378+
pub delete_method: SDMethod,
385379
}
386380

387381
#[derive(Debug, clap::Args)]
388382
pub struct BrokenFilesArgs {
389383
#[clap(flatten)]
390384
pub common_cli_items: CommonCliItems,
391-
#[clap(short = 'D', long, help = "Delete found files")]
392-
pub delete_files: bool,
385+
#[clap(flatten)]
386+
pub delete_method: SDMethod,
393387
#[clap(
394388
short,
395389
long,
@@ -412,8 +406,6 @@ pub struct SimilarVideosArgs {
412406
#[clap(flatten)]
413407
pub allow_hard_links: AllowHardLinks,
414408
#[clap(flatten)]
415-
pub dry_run: DryRun,
416-
#[clap(flatten)]
417409
pub ignore_same_size: IgnoreSameSize,
418410
#[clap(
419411
short,
@@ -531,15 +523,15 @@ pub struct CommonCliItems {
531523
pub disable_cache: bool,
532524
}
533525

534-
#[derive(Debug, clap::Args)]
526+
#[derive(Debug, clap::Args, Clone, Copy)]
535527
pub struct DoNotPrint {
536528
#[clap(short = 'N', long, help = "Do not print the results to the console")]
537529
pub do_not_print_results: bool,
538530
#[clap(short = 'M', long, help = "Do not print info/warnings/errors from the program to console")]
539531
pub do_not_print_messages: bool,
540532
}
541533

542-
#[derive(Debug, clap::Args)]
534+
#[derive(Debug, clap::Args, Clone, Copy)]
543535
pub struct DMethod {
544536
#[clap(
545537
short = 'D',
@@ -550,6 +542,21 @@ pub struct DMethod {
550542
long_help = "Methods to delete the files.\nAEN - All files except the newest,\nAEO - All files except the oldest,\nON - Only 1 file, the newest,\nOO - Only 1 file, the oldest\nAEB - All files except the biggest,\nAES - All files except the smallest,\nOB - Only 1 file, the biggest,\nOS - Only 1 file, the smallest\nHARD - create hard link\nNONE - not delete files"
551543
)]
552544
pub delete_method: DeleteMethod,
545+
#[clap(short = 'Q', long, help = "Do nothing and print the operation that would happen.")]
546+
pub dry_run: bool,
547+
#[clap(short = 'y', long, help = "Remove items to trash")]
548+
pub move_to_trash: bool,
549+
}
550+
551+
// Simple delete method - delete files or not
552+
#[derive(Debug, clap::Args, Clone, Copy)]
553+
pub struct SDMethod {
554+
#[clap(short = 'D', long, help = "Delete found items")]
555+
pub delete_files: bool,
556+
#[clap(short = 'Q', long, help = "Do nothing and print the operation that would happen.")]
557+
pub dry_run: bool,
558+
#[clap(short = 'y', long, help = "Remove items to trash")]
559+
pub move_to_trash: bool,
553560
}
554561

555562
#[derive(Debug, clap::Args)]
@@ -593,12 +600,6 @@ pub struct CaseSensitiveNameComparison {
593600
pub case_sensitive_name_comparison: bool,
594601
}
595602

596-
#[derive(Debug, clap::Args)]
597-
pub struct DryRun {
598-
#[clap(long, help = "Do nothing and print the operation that would happen.")]
599-
pub dry_run: bool,
600-
}
601-
602603
#[derive(Debug, clap::Args)]
603604
pub struct IgnoreSameSize {
604605
#[clap(short = 'J', long, help = "Ignore files with the same size, leaving only one file of each size")]

czkawka_cli/src/main.rs

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ use czkawka_core::tools::temporary::Temporary;
2828
use log::{debug, error, info};
2929

3030
use crate::commands::{
31-
Args, BadExtensionsArgs, BiggestFilesArgs, BrokenFilesArgs, CommonCliItems, DuplicatesArgs, EmptyFilesArgs, EmptyFoldersArgs, InvalidSymlinksArgs, SameMusicArgs,
32-
SimilarImagesArgs, SimilarVideosArgs, TemporaryArgs,
31+
Args, BadExtensionsArgs, BiggestFilesArgs, BrokenFilesArgs, CommonCliItems, DMethod, DuplicatesArgs, EmptyFilesArgs, EmptyFoldersArgs, InvalidSymlinksArgs, SDMethod,
32+
SameMusicArgs, SimilarImagesArgs, SimilarVideosArgs, TemporaryArgs,
3333
};
3434
use crate::progress::connect_progress;
3535

@@ -116,7 +116,6 @@ fn duplicates(duplicates: DuplicatesArgs, stop_flag: &Arc<AtomicBool>, progress_
116116
delete_method,
117117
hash_type,
118118
allow_hard_links,
119-
dry_run,
120119
case_sensitive_name_comparison,
121120
minimal_prehash_cache_file_size,
122121
use_prehash_cache,
@@ -136,23 +135,20 @@ fn duplicates(duplicates: DuplicatesArgs, stop_flag: &Arc<AtomicBool>, progress_
136135
set_common_settings(&mut tool, &common_cli_items, Some(reference_directories.reference_directories.as_ref()));
137136
tool.set_minimal_file_size(minimal_file_size);
138137
tool.set_maximal_file_size(maximal_file_size);
139-
tool.set_delete_method(delete_method.delete_method);
140-
tool.set_dry_run(dry_run.dry_run);
138+
set_advanced_delete(&mut tool, delete_method);
141139

142140
tool.search(stop_flag, Some(progress_sender));
143141

144142
save_and_write_results_to_writer(&tool, &common_cli_items)
145143
}
146144

147145
fn empty_folders(empty_folders: EmptyFoldersArgs, stop_flag: &Arc<AtomicBool>, progress_sender: &Sender<ProgressData>) -> CliOutput {
148-
let EmptyFoldersArgs { common_cli_items, delete_folders } = empty_folders;
146+
let EmptyFoldersArgs { common_cli_items, delete_method } = empty_folders;
149147

150148
let mut tool = EmptyFolder::new();
151149

152150
set_common_settings(&mut tool, &common_cli_items, None);
153-
if delete_folders {
154-
tool.set_delete_method(DeleteMethod::Delete);
155-
}
151+
set_simple_delete(&mut tool, delete_method);
156152

157153
tool.search(stop_flag, Some(progress_sender));
158154

@@ -163,7 +159,7 @@ fn biggest_files(biggest_files: BiggestFilesArgs, stop_flag: &Arc<AtomicBool>, p
163159
let BiggestFilesArgs {
164160
common_cli_items,
165161
number_of_files,
166-
delete_files,
162+
delete_method,
167163
smallest_mode,
168164
} = biggest_files;
169165

@@ -172,39 +168,33 @@ fn biggest_files(biggest_files: BiggestFilesArgs, stop_flag: &Arc<AtomicBool>, p
172168
let mut tool = BigFile::new(params);
173169

174170
set_common_settings(&mut tool, &common_cli_items, None);
175-
if delete_files {
176-
tool.set_delete_method(DeleteMethod::Delete);
177-
}
171+
set_simple_delete(&mut tool, delete_method);
178172

179173
tool.search(stop_flag, Some(progress_sender));
180174

181175
save_and_write_results_to_writer(&tool, &common_cli_items)
182176
}
183177

184178
fn empty_files(empty_files: EmptyFilesArgs, stop_flag: &Arc<AtomicBool>, progress_sender: &Sender<ProgressData>) -> CliOutput {
185-
let EmptyFilesArgs { common_cli_items, delete_files } = empty_files;
179+
let EmptyFilesArgs { common_cli_items, delete_method } = empty_files;
186180

187181
let mut tool = EmptyFiles::new();
188182

189183
set_common_settings(&mut tool, &common_cli_items, None);
190-
if delete_files {
191-
tool.set_delete_method(DeleteMethod::Delete);
192-
}
184+
set_simple_delete(&mut tool, delete_method);
193185

194186
tool.search(stop_flag, Some(progress_sender));
195187

196188
save_and_write_results_to_writer(&tool, &common_cli_items)
197189
}
198190

199191
fn temporary(temporary: TemporaryArgs, stop_flag: &Arc<AtomicBool>, progress_sender: &Sender<ProgressData>) -> CliOutput {
200-
let TemporaryArgs { common_cli_items, delete_files } = temporary;
192+
let TemporaryArgs { common_cli_items, delete_method } = temporary;
201193

202194
let mut tool = Temporary::new();
203195

204196
set_common_settings(&mut tool, &common_cli_items, None);
205-
if delete_files {
206-
tool.set_delete_method(DeleteMethod::Delete);
207-
}
197+
set_simple_delete(&mut tool, delete_method);
208198

209199
tool.search(stop_flag, Some(progress_sender));
210200

@@ -222,7 +212,6 @@ fn similar_images(similar_images: SimilarImagesArgs, stop_flag: &Arc<AtomicBool>
222212
image_filter,
223213
hash_size,
224214
delete_method,
225-
dry_run,
226215
allow_hard_links,
227216
ignore_same_size,
228217
} = similar_images;
@@ -241,8 +230,7 @@ fn similar_images(similar_images: SimilarImagesArgs, stop_flag: &Arc<AtomicBool>
241230
set_common_settings(&mut tool, &common_cli_items, Some(reference_directories.reference_directories.as_ref()));
242231
tool.set_minimal_file_size(minimal_file_size);
243232
tool.set_maximal_file_size(maximal_file_size);
244-
tool.set_delete_method(delete_method.delete_method);
245-
tool.set_dry_run(dry_run.dry_run);
233+
set_advanced_delete(&mut tool, delete_method);
246234

247235
tool.search(stop_flag, Some(progress_sender));
248236

@@ -257,7 +245,6 @@ fn same_music(same_music: SameMusicArgs, stop_flag: &Arc<AtomicBool>, progress_s
257245
minimal_file_size,
258246
maximal_file_size,
259247
music_similarity,
260-
dry_run,
261248
minimum_segment_duration,
262249
maximum_difference,
263250
search_method,
@@ -278,23 +265,20 @@ fn same_music(same_music: SameMusicArgs, stop_flag: &Arc<AtomicBool>, progress_s
278265
set_common_settings(&mut tool, &common_cli_items, Some(reference_directories.reference_directories.as_ref()));
279266
tool.set_minimal_file_size(minimal_file_size);
280267
tool.set_maximal_file_size(maximal_file_size);
281-
tool.set_delete_method(delete_method.delete_method);
282-
tool.set_dry_run(dry_run.dry_run);
268+
set_advanced_delete(&mut tool, delete_method);
283269

284270
tool.search(stop_flag, Some(progress_sender));
285271

286272
save_and_write_results_to_writer(&tool, &common_cli_items)
287273
}
288274

289275
fn invalid_symlinks(invalid_symlinks: InvalidSymlinksArgs, stop_flag: &Arc<AtomicBool>, progress_sender: &Sender<ProgressData>) -> CliOutput {
290-
let InvalidSymlinksArgs { common_cli_items, delete_files } = invalid_symlinks;
276+
let InvalidSymlinksArgs { common_cli_items, delete_method } = invalid_symlinks;
291277

292278
let mut tool = InvalidSymlinks::new();
293279

294280
set_common_settings(&mut tool, &common_cli_items, None);
295-
if delete_files {
296-
tool.set_delete_method(DeleteMethod::Delete);
297-
}
281+
set_simple_delete(&mut tool, delete_method);
298282

299283
tool.search(stop_flag, Some(progress_sender));
300284

@@ -304,7 +288,7 @@ fn invalid_symlinks(invalid_symlinks: InvalidSymlinksArgs, stop_flag: &Arc<Atomi
304288
fn broken_files(broken_files: BrokenFilesArgs, stop_flag: &Arc<AtomicBool>, progress_sender: &Sender<ProgressData>) -> CliOutput {
305289
let BrokenFilesArgs {
306290
common_cli_items,
307-
delete_files,
291+
delete_method,
308292
checked_types,
309293
} = broken_files;
310294

@@ -316,9 +300,7 @@ fn broken_files(broken_files: BrokenFilesArgs, stop_flag: &Arc<AtomicBool>, prog
316300
let mut tool = BrokenFiles::new(params);
317301

318302
set_common_settings(&mut tool, &common_cli_items, None);
319-
if delete_files {
320-
tool.set_delete_method(DeleteMethod::Delete);
321-
}
303+
set_simple_delete(&mut tool, delete_method);
322304

323305
tool.search(stop_flag, Some(progress_sender));
324306

@@ -333,7 +315,6 @@ fn similar_videos(similar_videos: SimilarVideosArgs, stop_flag: &Arc<AtomicBool>
333315
minimal_file_size,
334316
maximal_file_size,
335317
delete_method,
336-
dry_run,
337318
allow_hard_links,
338319
ignore_same_size,
339320
skip_forward_amount,
@@ -354,8 +335,7 @@ fn similar_videos(similar_videos: SimilarVideosArgs, stop_flag: &Arc<AtomicBool>
354335
set_common_settings(&mut tool, &common_cli_items, Some(reference_directories.reference_directories.as_ref()));
355336
tool.set_minimal_file_size(minimal_file_size);
356337
tool.set_maximal_file_size(maximal_file_size);
357-
tool.set_delete_method(delete_method.delete_method);
358-
tool.set_dry_run(dry_run.dry_run);
338+
set_advanced_delete(&mut tool, delete_method);
359339

360340
tool.search(stop_flag, Some(progress_sender));
361341

@@ -420,6 +400,26 @@ fn save_and_write_results_to_writer<T: CommonData + PrintResults>(component: &T,
420400
cli_output
421401
}
422402

403+
fn set_simple_delete<T>(component: &mut T, s_delete: SDMethod)
404+
where
405+
T: AllTraits,
406+
{
407+
if s_delete.delete_files {
408+
component.set_delete_method(DeleteMethod::Delete);
409+
}
410+
component.set_dry_run(s_delete.dry_run);
411+
component.set_move_to_trash(s_delete.move_to_trash);
412+
}
413+
414+
fn set_advanced_delete<T>(component: &mut T, a_delete: DMethod)
415+
where
416+
T: AllTraits,
417+
{
418+
component.set_delete_method(a_delete.delete_method);
419+
component.set_dry_run(a_delete.dry_run);
420+
component.set_move_to_trash(a_delete.move_to_trash);
421+
}
422+
423423
fn set_common_settings<T>(component: &mut T, common_cli_items: &CommonCliItems, reference_directories: Option<&Vec<PathBuf>>)
424424
where
425425
T: AllTraits,

czkawka_core/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ lofty = "0.22"
3333

3434
# Needed by broken files
3535
zip = { version = "6.0", features = ["aes-crypto", "bzip2", "deflate", "time"], default-features = false }
36-
audio_checker = "0.1"
3736
lopdf = "0.38.0"
3837

3938
# Needed by audio similarity feature

0 commit comments

Comments
 (0)