Skip to content

Commit b6870cc

Browse files
committed
Simplify copy or skip check by allowing clippy::unnecessary_unwrap
1 parent 8617e14 commit b6870cc

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

src/logic.rs

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -292,25 +292,22 @@ pub fn process_images(
292292
let file_size = src_path.metadata().expect("Expected file metadata.").len();
293293
let extension = src_path.extension();
294294

295-
// Copy or skip a file if it's not large enough, or if its extension is not supported,
296-
// or if it has no extension at all.
297-
if let Some(ext) = extension {
298-
if file_size >= min_size {
299-
match ext.to_string_lossy().to_lowercase().as_str() {
300-
"jpg" | "jpeg" => {
301-
match process_jpeg(src_path, &dst_path, resize, quality, &mut lock) {
302-
Ok(_) => print_success(src_path, &dst_path, different_paths, &mut lock),
303-
Err(err) => copy_or_skip(
304-
src_path,
305-
&dst_path,
306-
different_paths,
307-
&mut lock,
308-
Some(err),
309-
&mut has_error,
310-
),
311-
}
312-
}
313-
"png" => match process_png(src_path, &dst_path, resize, &mut lock) {
295+
// Copy or skip a file if it is not large enough, or has no extension, or if its extension is not supported.
296+
if file_size >= min_size && extension.is_some() {
297+
// This `allow` saves us a `copy_or_skip` call in terms of lines of code.
298+
// Namely, we can handle two cases at once: when file size is too small and when there is no extension,
299+
// but clippy doesn't know that so it emits a warning.
300+
// There is a commit with refactored code, but it has one more `copy_or_skip` call,
301+
// so we decided to revert to the original structure and added skipping of the lint.
302+
#[allow(clippy::unnecessary_unwrap)]
303+
match extension
304+
.expect("Expected a file extension")
305+
.to_string_lossy()
306+
.to_lowercase()
307+
.as_str()
308+
{
309+
"jpg" | "jpeg" => {
310+
match process_jpeg(src_path, &dst_path, resize, quality, &mut lock) {
314311
Ok(_) => print_success(src_path, &dst_path, different_paths, &mut lock),
315312
Err(err) => copy_or_skip(
316313
src_path,
@@ -320,25 +317,27 @@ pub fn process_images(
320317
Some(err),
321318
&mut has_error,
322319
),
323-
},
324-
_ => copy_or_skip(
320+
}
321+
}
322+
"png" => match process_png(src_path, &dst_path, resize, &mut lock) {
323+
Ok(_) => print_success(src_path, &dst_path, different_paths, &mut lock),
324+
Err(err) => copy_or_skip(
325325
src_path,
326326
&dst_path,
327327
different_paths,
328328
&mut lock,
329-
None,
329+
Some(err),
330330
&mut has_error,
331331
),
332-
}
333-
} else {
334-
copy_or_skip(
332+
},
333+
_ => copy_or_skip(
335334
src_path,
336335
&dst_path,
337336
different_paths,
338337
&mut lock,
339338
None,
340339
&mut has_error,
341-
);
340+
),
342341
}
343342
} else {
344343
copy_or_skip(

0 commit comments

Comments
 (0)