Skip to content

Commit 3e83764

Browse files
authored
fix: emit multiple events if multiple files are created at once for kqueue watcher (#54)
This PR fixes this bug found in Rolldown's test case. https://github.com/rolldown/rolldown/blob/6d37cd0ffd373aa3bd41f83e0591a8c2ab5a97d1/packages/rolldown/tests/watch/watch.test.ts#L72-L79 When multiple file creation was found at once, only the event for the first file was emitted. With this PR, the event for the non-first files are emitted.
1 parent de0a4b5 commit 3e83764

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

notify/src/kqueue.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,15 +251,15 @@ impl EventLoop {
251251
// list of known watches
252252
match std::fs::read_dir(&path) {
253253
Ok(dir) => {
254-
let file = dir
254+
let files = dir
255255
.filter_map(std::result::Result::ok)
256256
.map(|f| f.path())
257-
.find(|f| !self.watch_handles.contains(f));
258-
tracing::trace!(
259-
"new file detected: {:?}",
260-
file.as_ref().map(|f| f.display())
261-
);
262-
if let Some(file) = file {
257+
.filter(|f| !self.watch_handles.contains(f));
258+
let mut found_new_file = false;
259+
for file in files {
260+
found_new_file = true;
261+
tracing::trace!("new file detected: {}", file.display());
262+
263263
let metadata = file.metadata();
264264
let is_dir = metadata.as_ref().is_ok_and(|m| m.is_dir());
265265
if Self::is_watched_path(&self.watches, &file) {
@@ -276,8 +276,12 @@ impl EventLoop {
276276
}))
277277
.add_path(file),
278278
);
279+
break;
279280
}
280-
} else if Self::is_watched_path(&self.watches, &path) {
281+
}
282+
if !found_new_file
283+
&& Self::is_watched_path(&self.watches, &path)
284+
{
281285
evs.push(
282286
Event::new(EventKind::Modify(ModifyKind::Data(
283287
DataChange::Any,

0 commit comments

Comments
 (0)