mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-02 01:05:20 +03:00
Compare commits
1 Commits
bb184f8ea3
...
736f30e62c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
736f30e62c |
@ -11,7 +11,7 @@ from pathlib import Path
|
|||||||
from playhouse.sqlite_ext import SqliteExtDatabase
|
from playhouse.sqlite_ext import SqliteExtDatabase
|
||||||
|
|
||||||
from frigate.config import CameraConfig, FrigateConfig, RetainModeEnum
|
from frigate.config import CameraConfig, FrigateConfig, RetainModeEnum
|
||||||
from frigate.const import CACHE_DIR, CLIPS_DIR, MAX_WAL_SIZE, RECORD_DIR
|
from frigate.const import CACHE_DIR, CLIPS_DIR, MAX_WAL_SIZE
|
||||||
from frigate.models import Previews, Recordings, ReviewSegment, UserReviewStatus
|
from frigate.models import Previews, Recordings, ReviewSegment, UserReviewStatus
|
||||||
from frigate.util.builtin import clear_and_unlink
|
from frigate.util.builtin import clear_and_unlink
|
||||||
from frigate.util.media import remove_empty_directories
|
from frigate.util.media import remove_empty_directories
|
||||||
@ -376,5 +376,5 @@ class RecordingCleanup(threading.Thread):
|
|||||||
if counter == 0:
|
if counter == 0:
|
||||||
self.clean_tmp_clips()
|
self.clean_tmp_clips()
|
||||||
maybe_empty_dirs = self.expire_recordings()
|
maybe_empty_dirs = self.expire_recordings()
|
||||||
remove_empty_directories(Path(RECORD_DIR), maybe_empty_dirs)
|
remove_empty_directories(maybe_empty_dirs)
|
||||||
self.truncate_wal()
|
self.truncate_wal()
|
||||||
|
|||||||
@ -50,36 +50,22 @@ class SyncResult:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def remove_empty_directories(root: Path, paths: Iterable[Path]) -> None:
|
def remove_empty_directories(paths: Iterable[Path]) -> None:
|
||||||
"""
|
"""
|
||||||
Remove directories if they exist and are empty.
|
Remove directories if they exist and are empty.
|
||||||
Silently ignores non-existent and non-empty directories.
|
Silently ignores non-existent and non-empty directories.
|
||||||
Attempts to remove parent directories as well, stopping at the given root.
|
|
||||||
"""
|
"""
|
||||||
count = 0
|
count = 0
|
||||||
while True:
|
for path in paths:
|
||||||
parents = set()
|
try:
|
||||||
for path in paths:
|
path.rmdir()
|
||||||
if path == root:
|
except FileNotFoundError:
|
||||||
|
continue
|
||||||
|
except OSError as e:
|
||||||
|
if e.errno == errno.ENOTEMPTY:
|
||||||
continue
|
continue
|
||||||
|
raise
|
||||||
try:
|
count += 1
|
||||||
path.rmdir()
|
|
||||||
count += 1
|
|
||||||
except FileNotFoundError:
|
|
||||||
pass
|
|
||||||
except OSError as e:
|
|
||||||
if e.errno == errno.ENOTEMPTY:
|
|
||||||
continue
|
|
||||||
raise
|
|
||||||
|
|
||||||
parents.add(path.parent)
|
|
||||||
|
|
||||||
if not parents:
|
|
||||||
break
|
|
||||||
|
|
||||||
paths = parents
|
|
||||||
|
|
||||||
logger.debug("Removed {count} empty directories")
|
logger.debug("Removed {count} empty directories")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user