From 97c694a6548ab808108f47f77bfc0c666d86c383 Mon Sep 17 00:00:00 2001 From: Leo Vasanko Date: Sun, 12 Nov 2023 21:15:35 +0000 Subject: [PATCH] Correct locking on inotify watching, always use updates. --- cista/watching.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cista/watching.py b/cista/watching.py index b8d4ae8..d0a4988 100644 --- a/cista/watching.py +++ b/cista/watching.py @@ -1,6 +1,7 @@ import asyncio import shutil import stat +import sys import threading import time from os import stat_result @@ -147,11 +148,12 @@ def watcher_thread(loop): rootpath = config.config.path i = inotify.adapters.InotifyTree(rootpath.as_posix()) # Initialize the tree from filesystem - old, new = state.root, walk() - if old != new: - with state.lock: + new = walk() + with state.lock: + old = state.root + if old != new: state.root = new - broadcast(format_root(new), loop) + broadcast(format_update(old, new), loop) # The watching is not entirely reliable, so do a full refresh every minute refreshdl = time.monotonic() + 60.0 @@ -330,7 +332,7 @@ async def abroadcast(msg): async def start(app, loop): config.load_config() - use_inotify = False # sys.platform == "linux" + use_inotify = sys.platform == "linux" app.ctx.watcher = threading.Thread( target=watcher_thread if use_inotify else watcher_thread_poll, args=[loop],