plat/watch.rs#
Source: lib/plat/watch.rs
watch -- changes below folders, as they happen (continuous data protection)
Watcher::new(&roots) -> Result<Watcher, String> recursive; one thread watches; every
change after new returned is seen
watcher.take(wait_ms) -> Changes the paths changed since the last take
(waits up to wait_ms for the first);
overflow: events were lost, rescan
watcher.watching() -> bool every root (Linux: every folder) is
watched now; while not, each take
reports overflow (after its wait)
dropping the watcher stops it
Windows: ReadDirectoryChangesW per root (subtree, overlapped, 64 KiB buffer; an empty
answer means the buffer overflowed); new returns once every root's first read is pending
(a root that cannot be read fails it). A root whose read fails later (deleted, its drive
gone) is lost: it is opened again every second, and back it reports an overflow.
Linux: inotify with a watch per folder; new folders are added (and reported whole), a full
queue reports an overflow (after the whole tree is watched again: lost events may hide new
folders). A folder that could not be watched or listed for a passing reason (the watch
limit, no descriptors left) is tried again every second; a root moved or deleted ends its
watches (their events would name the old paths) and is watched again once a folder is at
its path. Until then watching() is false.
Android (docs/ANDROID.md AN3): the Linux way, on the app's names (android_files.rs: /data,
/documents ...; the watches on the real paths behind them); changes come back under those names.
macOS: FSEvents with file events (dropped events report an overflow); iOS: none.
Paths are absolute, in the form of the platform; the folder of a change is enough for a
caller that walks the tree again.
struct Changeswhat changed since the last takepaths: Vec<String>overflow: bool-- events were lost: everything below the roots may have changed
struct Watcher
impl Watcher
fn new(roots: &[String]) -> Result<Watcher, String>fn take(&self, wait_ms: u32) -> Changesthe changes so far (waiting up to wait_ms when there are none yet); while a root or folder is not watched (watching() false) overflow is set, after the waitfn watching(&self) -> boolwhether every root (Linux: every folder below them) is watched now; false while one is gone or could not be watched yet (the watcher tries again every second)