Introduce cross-platform file-watching (#6855)

This adds cross-platform file-watching via the
[Notify](https://github.com/notify-rs/notify) crate. The previous
fs-events implementation is now only used on MacOS, and on other
platforms Notify is used. The watching function interface is the same.

Related to #5391 #5395 #5394.

Release Notes:

- N/A
This commit is contained in:
Amin Yahyaabadi 2024-01-29 12:18:10 -08:00 committed by GitHub
parent b29f45ea68
commit 1313402a6b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 141 additions and 12 deletions

View file

@ -3221,10 +3221,7 @@ impl BackgroundScanner {
}
}
async fn run(
&mut self,
mut fs_events_rx: Pin<Box<dyn Send + Stream<Item = Vec<fsevent::Event>>>>,
) {
async fn run(&mut self, mut fs_events_rx: Pin<Box<dyn Send + Stream<Item = Vec<fs::Event>>>>) {
use futures::FutureExt as _;
// Populate ignores above the root.
@ -3271,9 +3268,10 @@ impl BackgroundScanner {
// have the previous state loaded yet.
self.phase = BackgroundScannerPhase::EventsReceivedDuringInitialScan;
if let Poll::Ready(Some(events)) = futures::poll!(fs_events_rx.next()) {
let mut paths = events.into_iter().map(|e| e.path).collect::<Vec<_>>();
let mut paths = fs::fs_events_paths(events);
while let Poll::Ready(Some(more_events)) = futures::poll!(fs_events_rx.next()) {
paths.extend(more_events.into_iter().map(|e| e.path));
paths.extend(fs::fs_events_paths(more_events));
}
self.process_events(paths).await;
}
@ -3312,9 +3310,10 @@ impl BackgroundScanner {
events = fs_events_rx.next().fuse() => {
let Some(events) = events else { break };
let mut paths = events.into_iter().map(|e| e.path).collect::<Vec<_>>();
let mut paths = fs::fs_events_paths(events);
while let Poll::Ready(Some(more_events)) = futures::poll!(fs_events_rx.next()) {
paths.extend(more_events.into_iter().map(|e| e.path));
paths.extend(fs::fs_events_paths(more_events));
}
self.process_events(paths.clone()).await;
}