diff --git a/CHANGELOG.md b/CHANGELOG.md index a0f92d20..b956653a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ - CHANGE: Make `Notice` events opt-in. - CHANGE: Remove `Sender`s from watcher API in favour of `EventFn` [#214] - META: The project maintainers have changed from @passcod to notify-rs. +- CHANGE: Avoid stating the watched path for non-recursive watches with inotify [#256] + +[#256]: https://github.com/notify-rs/notify/pull/256 ## 5.0.0-pre.3 (2020-06-22) diff --git a/src/inotify.rs b/src/inotify.rs index bdf8215a..14e59e3a 100644 --- a/src/inotify.rs +++ b/src/inotify.rs @@ -404,9 +404,9 @@ impl EventLoop { } fn add_watch(&mut self, path: PathBuf, is_recursive: bool, mut watch_self: bool) -> Result<()> { - let metadata = metadata(&path).map_err(Error::io)?; - - if !metadata.is_dir() || !is_recursive { + // If the watch is not recursive, or if we determine (by stat'ing the path to get its + // metadata) that the watched path is not a directory, add a single path watch. + if !is_recursive || !metadata(&path).map_err(Error::io)?.is_dir() { return self.add_single_watch(path, false, true); }