pub(super) fn nearest_existing_ancestor(path: &Path) -> Option<PathBuf>Expand description
Walk up path’s ancestors (parent, grandparent, …) and return the
first one that already exists on disk. Used by watch_agent when the
target directory doesn’t exist yet — notify::Watcher::watch fails
outright on a nonexistent path, so this finds the closest directory that
can actually be watched right now (a later-created descendant is still
picked up, since the watch is recursive).
Never walks above the user’s home directory. Without a floor, a fresh
environment where even ~/.config doesn’t exist yet (ephemeral
dev/CI/container — this project’s own docs describe several such setups)
would walk all the way to $HOME or further, and
watcher.watch(&watched_dir, RecursiveMode::Recursive) performs a
synchronous, blocking directory walk of whatever it’s handed — recursing
the entire home directory (or beyond) from inside the async
handle_reactive_register request handler risks a long stall and, on
Linux, exhausting the OS-wide inotify watch-count limit. Returns None
(giving up on watching rather than risking an unbounded walk) if path
isn’t under the home directory at all, or if no existing ancestor is
found within that bound.