From fc865ebc951c21160fba8cd3472ee0844e2898b4 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Mon, 23 Nov 2026 15:51:21 -0600 Subject: [PATCH] remove a deleted camera's recordings from disk Camera delete removed RECORD_DIR/ and CLIPS_DIR/, but recordings live under RECORD_DIR///, so the camera's segments stayed on disk after their rows were deleted and nothing reclaimed them. Neither path holds per-camera data, so they only matched when a camera name collided with something else, like a classification model's dataset, the thumbs or faces folders, or a date-named recordings folder. Delete now removes the and @sub folders under each recordings hour, plus the camera's thumbs, previews, lpr, and triggers folders. --- frigate/test/test_camera_lifecycle.py | 38 +++++++++++++++++++++++++++ frigate/util/camera_cleanup.py | 13 ++++++--- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/frigate/test/test_camera_lifecycle.py b/frigate/test/test_camera_lifecycle.py index 5184266dce..008490493b 100644 --- a/frigate/test/test_camera_lifecycle.py +++ b/frigate/test/test_camera_lifecycle.py @@ -264,3 +264,41 @@ class TestCameraFileCleanup(unittest.TestCase): ] self.assertEqual(remaining, other) + + def test_delete_removes_recordings_and_keeps_colliding_dirs(self): + own = [ + "recordings/2026-11-22/10/front/00.00.mp4", + "recordings/2026-11-22/10/front@sub/00.00.mp4", + "recordings/2026-11-23/03/front/10.00.mp4", + "clips/thumbs/front/a.webp", + "clips/previews/front/1.mp4", + "clips/lpr/front/a/1.jpg", + "clips/triggers/front/t.webp", + ] + other = [ + "recordings/2026-11-22/10/front_door/00.00.mp4", + "recordings/front/keep.mp4", + "clips/front/dataset/a.jpg", + "clips/thumbs/front_door/b.webp", + ] + + with tempfile.TemporaryDirectory() as root: + for name in own + other: + path = os.path.join(root, name) + os.makedirs(os.path.dirname(path), exist_ok=True) + open(path, "w").close() + + clips = os.path.join(root, "clips") + with patch.multiple( + camera_cleanup, + CLIPS_DIR=clips, + RECORD_DIR=os.path.join(root, "recordings"), + THUMB_DIR=os.path.join(clips, "thumbs"), + ): + camera_cleanup.cleanup_camera_files("front") + + remaining = [ + n for n in own + other if os.path.exists(os.path.join(root, n)) + ] + + self.assertEqual(remaining, other) diff --git a/frigate/util/camera_cleanup.py b/frigate/util/camera_cleanup.py index be0131fdec..835e90b61c 100644 --- a/frigate/util/camera_cleanup.py +++ b/frigate/util/camera_cleanup.py @@ -1,11 +1,12 @@ """Utilities for cleaning up camera data from database and filesystem.""" +import glob import logging import os import re import shutil -from frigate.const import CLIPS_DIR, RECORD_DIR, THUMB_DIR +from frigate.const import CLIPS_DIR, RECORD_DIR, SUB_CACHE_TAG, THUMB_DIR from frigate.models import ( Event, Export, @@ -112,12 +113,18 @@ def cleanup_camera_files( export_paths: Optional list of export file paths to remove """ dirs_to_clean = [ - os.path.join(RECORD_DIR, camera_name), - os.path.join(CLIPS_DIR, camera_name), os.path.join(THUMB_DIR, camera_name), os.path.join(CLIPS_DIR, "previews", camera_name), + os.path.join(CLIPS_DIR, "lpr", camera_name), + os.path.join(CLIPS_DIR, "triggers", camera_name), ] + # recordings live at RECORD_DIR/// + for name in (camera_name, f"{camera_name}{SUB_CACHE_TAG}"): + dirs_to_clean.extend( + glob.glob(os.path.join(glob.escape(RECORD_DIR), "*", "*", name)) + ) + for dir_path in dirs_to_clean: if os.path.exists(dir_path): try: