From c1d35b099bb7d5c307fb027acd65981d2fa506eb Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 27 Apr 2021 16:49:56 -0700 Subject: [PATCH] Ignore 'historical' events from fs event stream Co-Authored-By: Nathan Sobo --- fsevent/src/lib.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/fsevent/src/lib.rs b/fsevent/src/lib.rs index 481cceb8b6..202c7d7c0f 100644 --- a/fsevent/src/lib.rs +++ b/fsevent/src/lib.rs @@ -148,19 +148,25 @@ impl EventStream { let path_c_str = CStr::from_ptr(paths[p]); let path = PathBuf::from(OsStr::from_bytes(path_c_str.to_bytes())); if let Some(flag) = StreamFlags::from_bits(flags[p]) { - events.push(Event { - event_id: ids[p], - flags: flag, - path, - }); + if flag.contains(StreamFlags::HISTORY_DONE) { + events.clear(); + } else { + events.push(Event { + event_id: ids[p], + flags: flag, + path, + }); + } } else { debug_assert!(false, "unknown flag set for fs event: {}", flags[p]); } } - if !callback(events) { - fs::FSEventStreamStop(stream_ref); - cf::CFRunLoopStop(cf::CFRunLoopGetCurrent()); + if !events.is_empty() { + if !callback(events) { + fs::FSEventStreamStop(stream_ref); + cf::CFRunLoopStop(cf::CFRunLoopGetCurrent()); + } } } }