From 1dbddb28eed8a8492c9cb0231d23e2fca2034205 Mon Sep 17 00:00:00 2001 From: Stu Hood Date: Tue, 14 Jul 2020 13:19:10 -0700 Subject: [PATCH 1/2] Do not stat a path if not recursive. --- src/inotify.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/inotify.rs b/src/inotify.rs index bdf8215a..4cefbf17 100644 --- a/src/inotify.rs +++ b/src/inotify.rs @@ -404,9 +404,7 @@ 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 !is_recursive || !metadata(&path).map_err(Error::io)?.is_dir() { return self.add_single_watch(path, false, true); } From 2ed20536fa830349088b95261c278251ad6766c9 Mon Sep 17 00:00:00 2001 From: Stu Hood Date: Wed, 15 Jul 2020 22:00:24 -0700 Subject: [PATCH 2/2] Review feedback. --- CHANGELOG.md | 3 +++ src/inotify.rs | 2 ++ 2 files changed, 5 insertions(+) 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 4cefbf17..14e59e3a 100644 --- a/src/inotify.rs +++ b/src/inotify.rs @@ -404,6 +404,8 @@ impl EventLoop { } fn add_watch(&mut self, path: PathBuf, is_recursive: bool, mut watch_self: bool) -> Result<()> { + // 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); }