diff --git a/notify-debouncer-full/src/lib.rs b/notify-debouncer-full/src/lib.rs index bfb97b27..89fdbaea 100644 --- a/notify-debouncer-full/src/lib.rs +++ b/notify-debouncer-full/src/lib.rs @@ -226,18 +226,18 @@ impl DebounceDataInner { 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); @@ -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", diff --git a/notify-debouncer-full/test_cases/debounce_modify_events.hjson b/notify-debouncer-full/test_cases/debounce_modify_events.hjson new file mode 100644 index 00000000..3756ab83 --- /dev/null +++ b/notify-debouncer-full/test_cases/debounce_modify_events.hjson @@ -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 } + ] + } + } +} diff --git a/notify-debouncer-full/test_cases/emit_continuous_modify_content_events.hjson b/notify-debouncer-full/test_cases/emit_continuous_modify_content_events.hjson index 72197279..a378baf7 100644 --- a/notify-debouncer-full/test_cases/emit_continuous_modify_content_events.hjson +++ b/notify-debouncer-full/test_cases/emit_continuous_modify_content_events.hjson @@ -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 } ]