pub struct FileWatcher { /* private fields */ }Expand description
Watches a set of files and resolves whenever something changes in their directories.
Reacting to the filesystem (rather than a SIGHUP/SIGUSR1) is what lets
cert-manager, Kubernetes secret mounts, and mv-into-place rotate files with
no extra signalling: they rewrite the file and the watcher fires.
Watches each file’s parent directory, not the file itself. Editors,
cert-manager, and K8s secret mounts replace files by atomic rename or symlink
swap, which changes the inode (and, for the K8s ..data symlink, fires on the
directory without ever naming the file), so a watch set directly on the path
would be missed.
Implementations§
Source§impl FileWatcher
impl FileWatcher
Sourcepub fn new(paths: &[PathBuf]) -> Result<Self>
pub fn new(paths: &[PathBuf]) -> Result<Self>
Start watching the parent directories of paths. Errors if the OS watcher
can’t be created or a directory can’t be watched (e.g. the inotify
instance/watch limit is hit). notify already falls back to a built-in
poll watcher on platforms without a native backend, so there’s no manual
polling here.