strix

A simple web UI for motion
git clone https://www.brianlane.com/git/strix
Log | Files | Refs | LICENSE

commit 517de779d2e34364474387700f6031aca0a1e138
parent f4a1ff98b5c80eb64cda18c8253b45fc3d9e87a2
Author: Brian C. Lane <bcl@brianlane.com>
Date:   Fri,  3 Jun 2022 17:04:10 -0700

Fix cleanup of leftover delete_queue contents

Diffstat:
Msrc/strix/__init__.py | 1+
Msrc/strix/events.py | 21+++++++++++++++++++++
2 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/src/strix/__init__.py b/src/strix/__init__.py @@ -122,6 +122,7 @@ def run(): events.EventCache.base_dir(base_dir) events.EventCache.keep(opts.keep_days) events.EventCache.check_cache(opts.check_cache) + events.EventCache.cleanup_dq() events.preload_cache(log, base_dir) # Start queue monitor and processing thread (starts its own Multiprocessing threads) diff --git a/src/strix/events.py b/src/strix/events.py @@ -36,6 +36,27 @@ class EventCacheClass: self._lock = threading.Lock() self._cache = {} + def cleanup_dq(self): + """ + Cleanup any delete_queue subdirectories that may be leftover from previous run + """ + + def dth_fn(dq_dirs): + for dq in dq_dirs: + if not dq.startswith(self._base_dir): + raise RuntimeError(f"Invalid dq path: {dq}") + + shutil.rmtree(dq, ignore_errors=True) + + base = os.path.join(self._base_dir, "delete_queue") + dq_dirs = [os.path.join(base, dq) for dq in os.listdir(base)] + + # Start a thread to do the actual delete in the background + dth = mp.Process(name="delete-thread", + target=dth_fn, + args=(dq_dirs,)) + dth.start() + def get(self, key): with self._lock: return self._cache[key]