Skip to content

Commit c685ea7

Browse files
authored
Skip all Modify events right after a Create event, unless it's a rename event (#701)
Fixes #671
1 parent e36d54e commit c685ea7

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
## debouncer-full 0.6.0 (unreleased)
1717
- FEATURE: allow `FileIdCache` trait implementations to choose ownership of the returned file-ids
1818
- FEATURE: added support for the [`flume`](https://docs.rs/flume) crate
19+
- FIX: skip all `Modify` events right after a `Create` event, unless it's a rename event [#701]
20+
21+
[#701]: https://github.com/notify-rs/notify/pull/701
1922

2023
## debouncer-mini 0.7.0 (unreleased)
2124
- FEATURE: added support for the [`flume`](https://docs.rs/flume) crate

notify-debouncer-full/src/lib.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -509,9 +509,15 @@ impl<T: FileIdCache> DebounceDataInner<T> {
509509
let path = &event.paths[0];
510510

511511
if let Some(queue) = self.queues.get_mut(path) {
512-
// skip duplicate create events and modifications right after creation
512+
// Skip duplicate create events and modifications right after creation.
513+
// This code relies on backends never emitting a `Modify` event with kind other than `Name` for a rename event.
513514
if match event.kind {
514-
EventKind::Modify(ModifyKind::Data(_) | ModifyKind::Metadata(_))
515+
EventKind::Modify(
516+
ModifyKind::Any
517+
| ModifyKind::Data(_)
518+
| ModifyKind::Metadata(_)
519+
| ModifyKind::Other,
520+
)
515521
| EventKind::Create(_) => !queue.was_created(),
516522
_ => true,
517523
} {
@@ -639,16 +645,14 @@ pub fn new_debouncer_opt<F: DebounceEventHandler, T: Watcher, C: FileIdCache + S
639645
Some(v) => {
640646
if v > timeout {
641647
return Err(Error::new(ErrorKind::Generic(format!(
642-
"Invalid tick_rate, tick rate {:?} > {:?} timeout!",
643-
v, timeout
648+
"Invalid tick_rate, tick rate {v:?} > {timeout:?} timeout!"
644649
))));
645650
}
646651
v
647652
}
648653
None => timeout.checked_div(tick_div).ok_or_else(|| {
649654
Error::new(ErrorKind::Generic(format!(
650-
"Failed to calculate tick as {:?}/{}!",
651-
timeout, tick_div
655+
"Failed to calculate tick as {timeout:?}/{tick_div}!"
652656
)))
653657
})?,
654658
};
@@ -782,6 +786,7 @@ mod tests {
782786
"add_create_event_after_remove_event",
783787
"add_create_dir_event_twice",
784788
"add_event_with_no_paths_is_ok",
789+
"add_modify_any_event_after_create_event",
785790
"add_modify_content_event_after_create_event",
786791
"add_rename_from_event",
787792
"add_rename_from_event_after_create_event",
@@ -868,7 +873,7 @@ mod tests {
868873
state
869874
.errors
870875
.iter()
871-
.map(|e| format!("{:?}", e))
876+
.map(|e| format!("{e:?}"))
872877
.collect::<Vec<_>>(),
873878
expected_errors
874879
.iter()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// https://github.com/notify-rs/notify/issues/671
2+
3+
// Windows may emit a Create Any and then a Modify Anyevent when a file is created.
4+
{
5+
state: {
6+
queues: {
7+
/watch/file: {
8+
events: [
9+
{ kind: "create-any", paths: ["*"] }
10+
]
11+
}
12+
}
13+
}
14+
events: [
15+
{ kind: "modify-any", paths: ["/watch/file"] }
16+
]
17+
expected: {
18+
queues: {
19+
/watch/file: {
20+
events: [
21+
{ kind: "create-any", paths: ["*"] }
22+
]
23+
}
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)