Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions notify-debouncer-full/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,18 +226,18 @@ impl<T: FileIdCache> DebounceDataInner<T> {
let mut kind_index = HashMap::new();

while let Some(event) = queue.events.pop_front() {
if now.saturating_duration_since(event.time) >= self.timeout {
// remove previous event of the same kind
if let Some(idx) = kind_index.get(&event.kind).copied() {
events_expired.remove(idx);

kind_index.values_mut().for_each(|i| {
if *i > idx {
*i -= 1
}
})
}
// remove previous event of the same kind
if let Some(idx) = kind_index.get(&event.kind).copied() {
events_expired.remove(idx);

kind_index.values_mut().for_each(|i| {
if *i > idx {
*i -= 1
}
})
}

if now.saturating_duration_since(event.time) >= self.timeout {
kind_index.insert(event.kind, events_expired.len());

events_expired.push(event);
Expand Down Expand Up @@ -812,6 +812,7 @@ mod tests {
"add_remove_event_after_create_and_modify_event",
"add_remove_parent_event_after_remove_child_event",
"add_errors",
"debounce_modify_events",
"emit_continuous_modify_content_events",
"emit_events_in_chronological_order",
"emit_events_with_a_prepended_rename_event",
Expand Down
45 changes: 45 additions & 0 deletions notify-debouncer-full/test_cases/debounce_modify_events.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
state: {
timeout: 3
}
events: [
{ kind: "modify-any", paths: ["/watch/file"], time: 2 }
{ kind: "modify-any", paths: ["/watch/file"], time: 4 }
]
expected: {
queues: {
/watch/file: {
events: [
{ kind: "modify-any", paths: ["*"], time: 2 }
{ kind: "modify-any", paths: ["*"], time: 4 }
]
}
}
events: {
1: []
2: []
3: []
4: []
5: []
6: []
7: [
{ kind: "modify-any", paths: ["/watch/file"], time: 4 }
]
8: [
{ kind: "modify-any", paths: ["/watch/file"], time: 4 }
]
9: [
{ kind: "modify-any", paths: ["/watch/file"], time: 4 }
]
10: [
{ kind: "modify-any", paths: ["/watch/file"], time: 4 }
]
100: [
{ kind: "modify-any", paths: ["/watch/file"], time: 4 }
]
1000: [
{ kind: "modify-any", paths: ["/watch/file"], time: 4 }
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@
3: []
4: []
5: []
6: [
{ kind: "modify-data-content", paths: ["/watch/file"], time: 1 }
]
7: [
{ kind: "modify-data-content", paths: ["/watch/file"], time: 2 }
]
6: []
7: []
8: [
{ kind: "modify-data-content", paths: ["/watch/file"], time: 3 }
]
Expand Down