Skip to content

Commit a852bc9

Browse files
authored
refactor: use Path::ancestors (#64)
1 parent 3fbd975 commit a852bc9

File tree

2 files changed

+12
-24
lines changed

2 files changed

+12
-24
lines changed

notify/src/inotify.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,13 @@ fn add_watch_by_event(
8989
return;
9090
}
9191

92-
let mut current = parent;
93-
while let Some(parent) = current.parent() {
94-
if let Some(watch_mode) = watches.get(parent)
92+
for ancestor in parent.ancestors().skip(1) {
93+
if let Some(watch_mode) = watches.get(ancestor)
9594
&& watch_mode.recursive_mode == RecursiveMode::Recursive
9695
{
9796
add_watches.push((path.to_owned(), true, is_file_without_hardlinks));
9897
return;
9998
}
100-
current = parent;
10199
}
102100
}
103101

@@ -256,16 +254,11 @@ impl EventLoop {
256254
return true;
257255
}
258256

259-
let mut current = parent;
260-
while let Some(parent) = current.parent() {
261-
if let Some(watch_mode) = watches.get(parent)
262-
&& watch_mode.recursive_mode == RecursiveMode::Recursive
263-
{
264-
return true;
265-
}
266-
current = parent;
267-
}
268-
false
257+
parent.ancestors().skip(1).any(|ancestor| {
258+
watches
259+
.get(ancestor)
260+
.is_some_and(|watch_mode| watch_mode.recursive_mode == RecursiveMode::Recursive)
261+
})
269262
}
270263

271264
#[expect(clippy::too_many_lines)]

notify/src/kqueue.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,16 +183,11 @@ impl EventLoop {
183183
return true;
184184
}
185185

186-
let mut current = parent;
187-
while let Some(parent) = current.parent() {
188-
if let Some(watch_mode) = watches.get(parent)
189-
&& watch_mode.recursive_mode == RecursiveMode::Recursive
190-
{
191-
return true;
192-
}
193-
current = parent;
194-
}
195-
false
186+
parent.ancestors().skip(1).any(|ancestor| {
187+
watches
188+
.get(ancestor)
189+
.is_some_and(|watch_mode| watch_mode.recursive_mode == RecursiveMode::Recursive)
190+
})
196191
}
197192

198193
#[expect(clippy::too_many_lines)]

0 commit comments

Comments
 (0)