Fix camera name prefix matching (#24992)

* only remove the deleted camera's media files

Camera deletion globbed snapshot, clean copy, and review thumbnail files by "{camera}-*", and camera names can contain "-", so deleting "front" also removed every one of those files for "front-door". Files are now matched on the full name, the camera followed by an event or review id.

* only use the camera's own preview frames for review descriptions

get_cache_frames matched cached preview frames by "preview_{camera}-", so when "front" had no frame after the review ended, the first "front-door" frame became the trailing frame and went into front's GenAI prompt. It now uses is_camera_preview_frame like the preview recorder and exports.

* keep cleaning up when a media directory can't be listed
This commit is contained in:
Josh Hawkins
2026-11-16 12:04:55 -06:00
committed by GitHub
parent 128729f5ac
commit f22278bcfa
3 changed files with 66 additions and 26 deletions
+34 -1
View File
@@ -1,10 +1,12 @@
"""Regression tests for runtime camera add and delete handling."""
import asyncio
import os
import tempfile
import threading
import unittest
from types import SimpleNamespace
from unittest.mock import MagicMock
from unittest.mock import MagicMock, patch
# LicensePlatePostProcessor is imported via the maintainer rather than from
# data_processing.post.license_plate, which circularly imports back through
@@ -16,6 +18,7 @@ from frigate.embeddings.maintainer import (
from frigate.ptz.autotrack import PtzAutoTracker
from frigate.review.maintainer import ReviewSegmentMaintainer
from frigate.track.object_processing import TrackedObjectProcessor
from frigate.util import camera_cleanup
def _make_processor() -> TrackedObjectProcessor:
@@ -231,3 +234,33 @@ class TestCameraStateAccessors(unittest.TestCase):
processor = _make_processor()
self.assertEqual(processor.get_current_frame_time("deleted_cam"), 0.0)
class TestCameraFileCleanup(unittest.TestCase):
def test_delete_keeps_media_of_camera_sharing_name_prefix(self):
own = [
"front-1700000000.123456-abc123.jpg",
"front-1700000000.123456-abc123-clean.webp",
"review/thumb-front-1700000000.5-abc123.webp",
]
other = [
"front-door-1700000000.123456-def456.jpg",
"front-door-1700000000.123456-def456-clean.webp",
"review/thumb-front-door-1700000000.5-def456.webp",
]
with tempfile.TemporaryDirectory() as clips:
os.makedirs(os.path.join(clips, "review"))
for name in own + other:
open(os.path.join(clips, name), "w").close()
with patch.multiple(
camera_cleanup, CLIPS_DIR=clips, RECORD_DIR=clips, THUMB_DIR=clips
):
camera_cleanup.cleanup_camera_files("front")
remaining = [
n for n in own + other if os.path.exists(os.path.join(clips, n))
]
self.assertEqual(remaining, other)