From a0714e5a06d5bb7b4da537fb0ec177170f77e337 Mon Sep 17 00:00:00 2001 From: sapphi-red <49056869+sapphi-red@users.noreply.github.com> Date: Thu, 25 Dec 2025 12:29:11 +0900 Subject: [PATCH] refactor: use `Path::ancestors` --- notify/src/inotify.rs | 21 +++++++-------------- notify/src/kqueue.rs | 15 +++++---------- 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/notify/src/inotify.rs b/notify/src/inotify.rs index a77cf8f1..4d5ed61f 100644 --- a/notify/src/inotify.rs +++ b/notify/src/inotify.rs @@ -89,15 +89,13 @@ fn add_watch_by_event( return; } - let mut current = parent; - while let Some(parent) = current.parent() { - if let Some(watch_mode) = watches.get(parent) + for ancestor in parent.ancestors().skip(1) { + if let Some(watch_mode) = watches.get(ancestor) && watch_mode.recursive_mode == RecursiveMode::Recursive { add_watches.push((path.to_owned(), true, is_file_without_hardlinks)); return; } - current = parent; } } @@ -256,16 +254,11 @@ impl EventLoop { return true; } - let mut current = parent; - while let Some(parent) = current.parent() { - if let Some(watch_mode) = watches.get(parent) - && watch_mode.recursive_mode == RecursiveMode::Recursive - { - return true; - } - current = parent; - } - false + parent.ancestors().skip(1).any(|ancestor| { + watches + .get(ancestor) + .is_some_and(|watch_mode| watch_mode.recursive_mode == RecursiveMode::Recursive) + }) } #[expect(clippy::too_many_lines)] diff --git a/notify/src/kqueue.rs b/notify/src/kqueue.rs index e34bbb59..4ac68b5e 100644 --- a/notify/src/kqueue.rs +++ b/notify/src/kqueue.rs @@ -183,16 +183,11 @@ impl EventLoop { return true; } - let mut current = parent; - while let Some(parent) = current.parent() { - if let Some(watch_mode) = watches.get(parent) - && watch_mode.recursive_mode == RecursiveMode::Recursive - { - return true; - } - current = parent; - } - false + parent.ancestors().skip(1).any(|ancestor| { + watches + .get(ancestor) + .is_some_and(|watch_mode| watch_mode.recursive_mode == RecursiveMode::Recursive) + }) } #[expect(clippy::too_many_lines)]