Compare commits

...
Author SHA1 Message Date
Josh Hawkins fc865ebc95 remove a deleted camera's recordings from disk
Camera delete removed RECORD_DIR/<camera> and CLIPS_DIR/<camera>, but recordings live under RECORD_DIR/<date>/<hour>/<camera>, 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 <camera> and <camera>@sub folders under each recordings hour, plus the camera's thumbs, previews, lpr, and triggers folders.
2026-11-23 15:51:21 -06:00
2 changed files with 48 additions and 3 deletions
+38
View File
@@ -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)
+10 -3
View File
@@ -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/<date>/<hour>/<camera>
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: