diff --git a/crates/pinakes-core/src/integrity.rs b/crates/pinakes-core/src/integrity.rs index 625bbe2..ff4bf9b 100644 --- a/crates/pinakes-core/src/integrity.rs +++ b/crates/pinakes-core/src/integrity.rs @@ -392,7 +392,13 @@ pub async fn cleanup_orphaned_thumbnails( if thumbnail_dir.exists() { let entries = std::fs::read_dir(thumbnail_dir)?; - for entry in entries.flatten() { + for entry in entries.filter_map(|e| { + e.map_err(|err| { + warn!(error = %err, "failed to read thumbnail directory entry"); + err + }) + .ok() + }) { let path = entry.path(); if let Some(stem) = path.file_stem().and_then(|s| s.to_str()) && !known_ids.contains(stem) diff --git a/crates/pinakes-core/src/scan.rs b/crates/pinakes-core/src/scan.rs index ce43896..31bab6e 100644 --- a/crates/pinakes-core/src/scan.rs +++ b/crates/pinakes-core/src/scan.rs @@ -271,7 +271,9 @@ pub async fn scan_directory_with_options( if let Some(p) = progress { p.record_error(msg.clone()); } - errors.push(msg); + if errors.len() < MAX_STORED_ERRORS { + errors.push(msg); + } }, } } diff --git a/crates/pinakes-core/src/storage/postgres.rs b/crates/pinakes-core/src/storage/postgres.rs index f9d2a43..76d84cd 100644 --- a/crates/pinakes-core/src/storage/postgres.rs +++ b/crates/pinakes-core/src/storage/postgres.rs @@ -3721,8 +3721,20 @@ impl StorageBackend for PostgresBackend { .map(|p| p.to_string_lossy().to_string()); let track_index = subtitle .track_index - .map(|i| i32::try_from(i).unwrap_or(i32::MAX)); - let offset_ms = i32::try_from(subtitle.offset_ms).unwrap_or(i32::MAX); + .map(|i| { + i32::try_from(i).map_err(|_| { + PinakesError::InvalidOperation(format!( + "subtitle track_index {i} exceeds i32 range" + )) + }) + }) + .transpose()?; + let offset_ms = i32::try_from(subtitle.offset_ms).map_err(|_| { + PinakesError::InvalidOperation(format!( + "subtitle offset_ms {} exceeds i32 range", + subtitle.offset_ms + )) + })?; client .execute( "INSERT INTO subtitles (id, media_id, language, format, file_path, \ @@ -3809,7 +3821,11 @@ impl StorageBackend for PostgresBackend { .get() .await .map_err(|e| PinakesError::Database(format!("pool error: {e}")))?; - let offset = i32::try_from(offset_ms).unwrap_or(i32::MAX); + let offset = i32::try_from(offset_ms).map_err(|_| { + PinakesError::InvalidOperation(format!( + "subtitle offset_ms {offset_ms} exceeds i32 range" + )) + })?; client .execute("UPDATE subtitles SET offset_ms = $1 WHERE id = $2", &[ &offset, &id, diff --git a/crates/pinakes-core/src/thumbnail.rs b/crates/pinakes-core/src/thumbnail.rs index 7e3b799..3c79b25 100644 --- a/crates/pinakes-core/src/thumbnail.rs +++ b/crates/pinakes-core/src/thumbnail.rs @@ -28,9 +28,10 @@ impl TempFileGuard { impl Drop for TempFileGuard { fn drop(&mut self) { if self.0.exists() - && let Err(e) = std::fs::remove_file(&self.0) { - warn!("failed to clean up temp file {}: {e}", self.0.display()); - } + && let Err(e) = std::fs::remove_file(&self.0) + { + warn!("failed to clean up temp file {}: {e}", self.0.display()); + } } }