watcher.py

clew/mcp_server/watcher.py

OS file-change events that wake the server's refresh loop the moment a file is saved.

sync

None clew.mcp_server.watcher.RepoWatcher.sync(self, set[str] roots)

Watch exactly these roots: schedule new ones, unschedule dropped ones.

clew/mcp_server/watcher.py:88

Show on the map →

Called by none

Calls _ensure_observer, _handler

Source · 23 lines
    def sync(self, roots: set[str]) -> None:
        """NEVER RAISES: a root that cannot be watched is logged and left to the interval sweep.

        @brief Reconcile the scheduled watches.
        @return None.
        @version 1
        """
        observer = self._ensure_observer()
        if observer is None:
            return
        for root in sorted(set(self._watches) - roots):
            observer.unschedule(self._watches.pop(root))
        for root in sorted(roots - set(self._watches)):
            try:
                self._watches[root] = observer.schedule(self._handler(), root, recursive=True)
            except Exception as exc:  # inotify limits, vanished directory, unsupported fs
                logger.warning(
                    "file watch on %s could not start (%s); its index is kept current by the "
                    "interval sweep instead",
                    root,
                    exc,
                )
Activity · 10 steps
lines 95–95observer = self._ensure_observer()lines 96–96◇ if observer is Nonelines 97–97returnlines 98–98◇ for root in sorted(set(self._watches) - roots)lines 99–99observer.unschedule(self._watches.pop(root))lines 100–100◇ for root in sorted(roots - set(self._watches))lines 101–101trylines 102–102self._watches[root] = observer.schedule(self._handler(), root, recursive=True)lines 103–103except Exception as exc: # inotify limits, vanished directory, unsupported fslines 104–109logger.warning( "file watch on %s could not start (%s); its index is kept current by the " "interval sweep instead", root, exc, )

Requirements

REQ-DDB-INDEX-006