cleanup empty directories

This commit is contained in:
Blake Blackshear 2020-11-30 21:08:47 -06:00
parent f5c4bfa7b4
commit feb42181de
3 changed files with 21 additions and 6 deletions

View File

@ -166,6 +166,7 @@ class EventProcessor(threading.Thread):
# if save clips is not enabled for this camera, just continue
if not save_clips_config.enabled:
if event_type == 'end':
self.event_processed_queue.put((event_data['id'], camera))
continue
@ -173,6 +174,7 @@ class EventProcessor(threading.Thread):
# TODO: default to all tracked objects rather than checking for None
if save_clips_config.objects:
if not event_data['label'] in save_clips_config.objects:
if event_type == 'end':
self.event_processed_queue.put((event_data['id'], camera))
continue

View File

@ -17,6 +17,18 @@ logger = logging.getLogger(__name__)
SECONDS_IN_DAY = 60 * 60 * 24
def remove_empty_directories(directory):
# list all directories recursively and sort them by path,
# longest first
paths = sorted(
[x[0] for x in os.walk('/media/frigate/recordings/')],
key=lambda p: len(str(p)),
reverse=True,
)
for path in paths:
if len(os.listdir(path)) == 0:
os.rmdir(path)
class RecordingMaintainer(threading.Thread):
def __init__(self, config: FrigateConfig, stop_event):
threading.Thread.__init__(self)
@ -103,8 +115,9 @@ class RecordingMaintainer(threading.Thread):
# only expire events every 10 minutes, but check for new files every 10 seconds
time.sleep(10)
counter = counter + 1
if counter < 60:
if counter > 60:
self.expire_files()
remove_empty_directories(self.record_dir)
counter = 0
self.move_files()