fix: skip corrupt/unreadable images instead of aborting scan
- scan_images now warns and continues on decode errors - new test: scan_skips_corrupt_image_files - 21 tests passing
This commit is contained in:
16
src/lib.rs
16
src/lib.rs
@@ -40,9 +40,21 @@ pub fn scan_images(root: &Path) -> Result<Vec<ImageEntry>> {
|
||||
if !entry.file_type().is_file() || !is_image_path(path) {
|
||||
continue;
|
||||
}
|
||||
let bytes = fs::read(path)?;
|
||||
let bytes = match fs::read(path) {
|
||||
Ok(b) => b,
|
||||
Err(e) => {
|
||||
eprintln!("warning: skipping {}: {e}", path.display());
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let sha256 = format!("{:x}", Sha256::digest(&bytes));
|
||||
let img = image::open(path)?;
|
||||
let img = match image::open(path) {
|
||||
Ok(i) => i,
|
||||
Err(e) => {
|
||||
eprintln!("warning: skipping {}: {e}", path.display());
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let dhash = compute_dhash(&img);
|
||||
out.push(ImageEntry {
|
||||
path: path.to_path_buf(),
|
||||
|
||||
Reference in New Issue
Block a user