diff --git a/fsevent/src/lib.rs b/fsevent/src/lib.rs index 202c7d7c0f..69ea21cdb0 100644 --- a/fsevent/src/lib.rs +++ b/fsevent/src/lib.rs @@ -82,6 +82,15 @@ impl EventStream { ); cf::CFRelease(cf_paths); + fs::FSEventStreamScheduleWithRunLoop( + stream, + cf::CFRunLoopGetCurrent(), + cf::kCFRunLoopDefaultMode, + ); + fs::FSEventStreamStart(stream); + fs::FSEventStreamFlushSync(stream); + fs::FSEventStreamStop(stream); + let state = Arc::new(Mutex::new(Lifecycle::New)); ( @@ -111,12 +120,8 @@ impl EventStream { } } fs::FSEventStreamScheduleWithRunLoop(self.stream, run_loop, cf::kCFRunLoopDefaultMode); - fs::FSEventStreamStart(self.stream); cf::CFRunLoopRun(); - - fs::FSEventStreamFlushSync(self.stream); - fs::FSEventStreamStop(self.stream); fs::FSEventStreamRelease(self.stream); } } @@ -133,11 +138,12 @@ impl EventStream { let event_paths = event_paths as *const *const ::std::os::raw::c_char; let e_ptr = event_flags as *mut u32; let i_ptr = event_ids as *mut u64; - let callback = (info as *mut Option) - .as_mut() - .unwrap() - .as_mut() - .unwrap(); + let callback_ptr = (info as *mut Option).as_mut().unwrap(); + let callback = if let Some(callback) = callback_ptr.as_mut() { + callback + } else { + return; + }; let paths = slice::from_raw_parts(event_paths, num); let flags = slice::from_raw_parts_mut(e_ptr, num);