in lib/src/directory_watcher/mac_os.dart [113:178]
void _onBatch(List<FileSystemEvent> batch) {
// If we get a batch of events before we're ready to begin emitting events,
// it's probable that it's a batch of pre-watcher events (see issue 14373).
// Ignore those events and re-list the directory.
if (!isReady) {
// Cancel the timer because bogus events only occur in the first batch, so
// we can fire [ready] as soon as we're done listing the directory.
_bogusEventTimer.cancel();
_listDir().then((_) {
if (!isReady) {
_readyCompleter.complete();
}
});
return;
}
_sortEvents(batch).forEach((path, eventSet) {
var canonicalEvent = _canonicalEvent(eventSet);
var events = canonicalEvent == null
? _eventsBasedOnFileSystem(path)
: [canonicalEvent];
for (var event in events) {
if (event is FileSystemCreateEvent) {
if (!event.isDirectory) {
// If we already know about the file, treat it like a modification.
// This can happen if a file is copied on top of an existing one.
// We'll see an ADD event for the latter file when from the user's
// perspective, the file's contents just changed.
var type =
_files.contains(path) ? ChangeType.MODIFY : ChangeType.ADD;
_emitEvent(type, path);
_files.add(path);
continue;
}
if (_files.containsDir(path)) continue;
var stream = Directory(path).list(recursive: true);
var subscription = stream.listen((entity) {
if (entity is Directory) return;
if (_files.contains(path)) return;
_emitEvent(ChangeType.ADD, entity.path);
_files.add(entity.path);
}, cancelOnError: true);
subscription.onDone(() {
_listSubscriptions.remove(subscription);
});
subscription.onError((Object e, StackTrace stackTrace) {
_emitError(e, stackTrace);
});
_listSubscriptions.add(subscription);
} else if (event is FileSystemModifyEvent) {
assert(!event.isDirectory);
_emitEvent(ChangeType.MODIFY, path);
} else {
assert(event is FileSystemDeleteEvent);
for (var removedPath in _files.remove(path)) {
_emitEvent(ChangeType.REMOVE, removedPath);
}
}
}
});
}