Skip to main content

Module config_watch

Module config_watch 

Source
Expand description

A watch on exactly one file - forge.toml - so an edit reaches a running forge without a restart.

The watch is on the file, never its directory: nothing else in the config dir can produce an event. An editor’s atomic save writes a temporary file and renames it over the path, and Syncthing applies an incoming change the same way, so the watch is re-armed on the path after every burst - a watch held on the replaced inode goes deaf.

A symlink repointed at a different target produces no event, because the backend watches the target’s directory. Replace the file through the link, or edit the path the config dir actually names.

Re-exportsΒ§

use std::path::Path; πŸ”’
use std::path::PathBuf; πŸ”’
use std::time::Duration; πŸ”’
use notify::RecommendedWatcher; πŸ”’
use notify::RecursiveMode; πŸ”’
use notify::Watcher as _; πŸ”’
use tokio::sync::mpsc::UnboundedSender; πŸ”’
use tokio::task::JoinHandle; πŸ”’

StructsΒ§

ConfigWatch
A live watch. Dropping it stops the task and with it the watcher.
WatchedPath πŸ”’
Both spellings of the watched path: FSEvents reports real paths, so a config dir reached through a symlink (/var on macOS) needs the canonical one to match.

ConstantsΒ§

DEBOUNCE πŸ”’
Coalescing window, measured from a burst’s first event. Later events inside it join the burst and do not extend it.
REARM_GRACE πŸ”’
How long the fast retries run before the missing path is reported.
REARM_RETRY πŸ”’
Re-arm retry while an atomic save has the path momentarily missing.
REARM_SLOW πŸ”’
Re-arm cadence after that, so a file that reappears later is still watched and its contents apply.

FunctionsΒ§

arm πŸ”’
arm_io πŸ”’
A notify failure as the io::Error the re-arm classifies on. std::io::Error::other would erase the one kind that matters here: a path an atomic save has momentarily removed is expected, and everything else is forge’s own problem.
event_matches πŸ”’
Whether one notify event means the watched file may have changed. A rescan says events were dropped and anything may have moved, and it carries no paths, so it is decided before the path test.
rearm_fast πŸ”’
Re-arm for up to REARM_GRACE, covering the gap an atomic save leaves. None means the path is still missing; the caller sends its notification anyway and slow_rearm keeps trying.
slow_rearm πŸ”’
The path was missing past the grace window: keep a slow watch attempt running so a file that comes back later is seen and applies.
unwatchable πŸ”’
watch
Watch path and send one () per burst of content changes to it.