Regression: inotify optional on unsupported platforms

This commit is contained in:
2026-05-05 02:32:47 +00:00
parent 1b2267587f
commit 536efc4ce1
+10 -3
View File
@@ -9,7 +9,6 @@ from os import stat_result
from pathlib import Path, PurePosixPath from pathlib import Path, PurePosixPath
from stat import S_ISDIR, S_ISREG from stat import S_ISDIR, S_ISREG
import inotify.adapters
import msgspec import msgspec
from natsort import humansorted, natsort_keygen, ns from natsort import humansorted, natsort_keygen, ns
from sanic.log import logger from sanic.log import logger
@@ -18,6 +17,11 @@ from cista import config
from cista.fileio import fuid from cista.fileio import fuid
from cista.protocol import FileEntry, Space, UpdDel, UpdIns, UpdKeep from cista.protocol import FileEntry, Space, UpdDel, UpdIns, UpdKeep
try:
import inotify.adapters as inotify_adapters
except Exception:
inotify_adapters = None
# Platform-specific allocated size calculation # Platform-specific allocated size calculation
if sys.platform == "win32": if sys.platform == "win32":
import ctypes import ctypes
@@ -665,10 +669,13 @@ DEBOUNCE_MAX = 0.1 # But no more than 100ms total
def watcher(loop): def watcher(loop):
"""Unified watcher thread handling inotify, websocket signals, and periodic scans.""" """Unified watcher thread handling inotify, websocket signals, and periodic scans."""
use_inotify = sys.platform == "linux" use_inotify = sys.platform == "linux" and inotify_adapters is not None
inotify_tree = None inotify_tree = None
modified_flags = frozenset() modified_flags = frozenset()
if sys.platform == "linux" and inotify_adapters is None:
logger.warning("inotify unavailable; falling back to periodic scanning")
if use_inotify: if use_inotify:
modified_flags = frozenset( modified_flags = frozenset(
( (
@@ -684,7 +691,7 @@ def watcher(loop):
while not stop_event.is_set(): while not stop_event.is_set():
if use_inotify: if use_inotify:
inotify_tree = inotify.adapters.InotifyTree(rootpath.as_posix()) inotify_tree = inotify_adapters.InotifyTree(rootpath.as_posix())
# Initialize the tree from filesystem # Initialize the tree from filesystem
try: try: