@@ -12,6 +12,7 @@ import '../path_set.dart';
12
12
import '../resubscribable.dart' ;
13
13
import '../utils.dart' ;
14
14
import '../watch_event.dart' ;
15
+ import '../watcher_filesystem_event.dart' ;
15
16
16
17
/// Uses the FSEvents subsystem to watch for filesystem events.
17
18
///
@@ -63,7 +64,7 @@ class _MacOSDirectoryWatcher
63
64
///
64
65
/// This is separate from [_listSubscriptions] because this stream
65
66
/// occasionally needs to be resubscribed in order to work around issue 14849.
66
- StreamSubscription <List <FileSystemEvent >>? _watchSubscription;
67
+ StreamSubscription <List <WatcherFilesystemEvent >>? _watchSubscription;
67
68
68
69
/// The subscription to the [Directory.list] call for the initial listing of
69
70
/// the directory to determine its initial state.
@@ -109,7 +110,7 @@ class _MacOSDirectoryWatcher
109
110
}
110
111
111
112
/// The callback that's run when [Directory.watch] emits a batch of events.
112
- void _onBatch (List <FileSystemEvent > batch) {
113
+ void _onBatch (List <WatcherFilesystemEvent > batch) {
113
114
// If we get a batch of events before we're ready to begin emitting events,
114
115
// it's probable that it's a batch of pre-watcher events (see issue 14373).
115
116
// Ignore those events and re-list the directory.
@@ -184,8 +185,9 @@ class _MacOSDirectoryWatcher
184
185
///
185
186
/// The returned events won't contain any [FileSystemMoveEvent] s, nor will it
186
187
/// contain any events relating to [path] .
187
- Map <String , Set <FileSystemEvent >> _sortEvents (List <FileSystemEvent > batch) {
188
- var eventsForPaths = < String , Set <FileSystemEvent >> {};
188
+ Map <String , Set <WatcherFilesystemEvent >> _sortEvents (
189
+ List <WatcherFilesystemEvent > batch) {
190
+ var eventsForPaths = < String , Set <WatcherFilesystemEvent >> {};
189
191
190
192
// FSEvents can report past events, including events on the root directory
191
193
// such as it being created. We want to ignore these. If the directory is
@@ -196,22 +198,18 @@ class _MacOSDirectoryWatcher
196
198
// directory's full contents will be examined anyway, so we ignore such
197
199
// events. Emitting them could cause useless or out-of-order events.
198
200
var directories = unionAll (batch.map ((event) {
199
- if (! event.isDirectory) return < String > {};
200
- if (event is FileSystemMoveEvent ) {
201
- var destination = event.destination;
202
- if (destination != null ) {
203
- return {event.path, destination};
204
- }
205
- }
206
- return {event.path};
201
+ if (event.isDirectory == false ) return < String > {};
202
+ return event.paths;
207
203
}));
208
204
209
205
bool isInModifiedDirectory (String path) =>
210
206
directories.any ((dir) => path != dir && p.isWithin (dir, path));
211
207
212
- void addEvent (String path, FileSystemEvent event) {
208
+ void addEvent (String path, WatcherFilesystemEvent event) {
213
209
if (isInModifiedDirectory (path)) return ;
214
- eventsForPaths.putIfAbsent (path, () => < FileSystemEvent > {}).add (event);
210
+ eventsForPaths
211
+ .putIfAbsent (path, () => < WatcherFilesystemEvent > {})
212
+ .add (event);
215
213
}
216
214
217
215
for (var event in batch) {
@@ -233,29 +231,29 @@ class _MacOSDirectoryWatcher
233
231
/// If [batch] does contain contradictory events, this returns `null` to
234
232
/// indicate that the state of the path on the filesystem should be checked to
235
233
/// determine what occurred.
236
- FileSystemEvent ? _canonicalEvent (Set <FileSystemEvent > batch) {
234
+ WatcherFilesystemEvent ? _canonicalEvent (Set <WatcherFilesystemEvent > batch) {
237
235
// An empty batch indicates that we've learned earlier that the batch is
238
236
// contradictory (e.g. because of a move).
239
237
if (batch.isEmpty) return null ;
240
238
241
239
var type = batch.first.type;
242
- var isDir = batch.first.isDirectory;
240
+ var isDirectory = batch.first.isDirectory;
243
241
var hadModifyEvent = false ;
244
242
245
243
for (var event in batch.skip (1 )) {
246
244
// If one event reports that the file is a directory and another event
247
245
// doesn't, that's a contradiction.
248
- if (isDir != event.isDirectory) return null ;
246
+ if (isDirectory != event.isDirectory) return null ;
249
247
250
248
// Modify events don't contradict either CREATE or REMOVE events. We can
251
249
// safely assume the file was modified after a CREATE or before the
252
250
// REMOVE; otherwise there will also be a REMOVE or CREATE event
253
251
// (respectively) that will be contradictory.
254
- if (event is FileSystemModifyEvent ) {
252
+ if (event.isModify ) {
255
253
hadModifyEvent = true ;
256
254
continue ;
257
255
}
258
- assert (event is FileSystemCreateEvent || event is FileSystemDeleteEvent );
256
+ assert (event.isCreate || event.isDelete );
259
257
260
258
// If we previously thought this was a MODIFY, we now consider it to be a
261
259
// CREATE or REMOVE event. This is safe for the same reason as above.
@@ -285,12 +283,14 @@ class _MacOSDirectoryWatcher
285
283
// that the directory was moved and then re-created.
286
284
// [_eventsBasedOnFileSystem] will handle this correctly by producing a
287
285
// DELETE event followed by a CREATE event if the directory exists.
288
- if (isDir) return null ;
289
- return FileSystemCreateEvent (batch.first.path, false );
286
+ if (isDirectory! ) return null ;
287
+ return WatcherFilesystemEvent .create (batch.first.path,
288
+ isDirectory: false );
290
289
case FileSystemEvent .delete:
291
- return FileSystemDeleteEvent (batch.first.path, isDir );
290
+ return WatcherFilesystemEvent . delete (batch.first.path);
292
291
case FileSystemEvent .modify:
293
- return FileSystemModifyEvent (batch.first.path, isDir, false );
292
+ return WatcherFilesystemEvent .modify (batch.first.path,
293
+ isDirectory: isDirectory! );
294
294
default :
295
295
throw StateError ('unreachable' );
296
296
}
0 commit comments