@@ -205,7 +205,7 @@ class _MacOSDirectoryWatcher
205
205
// as the directory's full content will be listed.
206
206
var createdDirectories = unionAll (batch.map ((event) {
207
207
return event.type == EventType .createDirectory
208
- ? event.paths
208
+ ? { event.path}
209
209
: const < String > {};
210
210
}));
211
211
@@ -241,73 +241,26 @@ class _MacOSDirectoryWatcher
241
241
/// indicate that the state of the path on the filesystem should be checked to
242
242
/// determine what occurred.
243
243
Event ? _canonicalEvent (Set <Event > batch) {
244
- // An empty batch indicates that we've learned earlier that the batch is
245
- // contradictory (e.g. because of a move).
246
244
if (batch.isEmpty) return null ;
247
245
248
- var path = batch.first.path;
249
- var type = batch.first.type;
250
- var isDirectory = batch.first.isDirectory;
251
- var hadModifyEvent = false ;
252
-
253
- for (var event in batch.skip (1 )) {
254
- // If one event reports that the file is a directory and another event
255
- // doesn't, that's a contradiction.
256
- if (isDirectory != event.isDirectory) return null ;
257
-
258
- // Modify events don't contradict either CREATE or REMOVE events. We can
259
- // safely assume the file was modified after a CREATE or before the
260
- // REMOVE; otherwise there will also be a REMOVE or CREATE event
261
- // (respectively) that will be contradictory.
262
- if (event.type == EventType .modifyFile) {
263
- hadModifyEvent = true ;
264
- continue ;
265
- }
266
- assert (event.isCreate || event.isDelete);
246
+ var types = batch.map ((e) => e.type).toSet ();
267
247
268
- // If we previously thought this was a MODIFY, we now consider it to be a
269
- // CREATE or REMOVE event. This is safe for the same reason as above.
270
- if (type == EventType .modifyFile) {
271
- type = event.type;
272
- continue ;
248
+ if (types.length == 2 &&
249
+ types.contains (EventType .modifyFile) &&
250
+ types.contains (EventType .createFile)) {
251
+ if (_files.contains (path)) {
252
+ types.remove (EventType .createFile);
253
+ } else {
254
+ types.remove (EventType .modifyFile);
273
255
}
274
-
275
- // A CREATE event contradicts a REMOVE event and vice versa.
276
- assert (type == EventType .createFile ||
277
- type == EventType .createDirectory ||
278
- type == EventType .delete);
279
- if (type != event.type) return null ;
280
256
}
281
257
282
- // If we got a CREATE event for a file we already knew about, that comes
283
- // from FSEvents reporting an add that happened prior to the watch
284
- // beginning. If we also received a MODIFY event, we want to report that,
285
- // but not the CREATE.
286
- if (type == EventType .createFile &&
287
- hadModifyEvent &&
288
- _files.contains (path)) {
289
- type = EventType .modifyFile;
258
+ if (types.length != 1 ) {
259
+ return null ;
290
260
}
291
261
292
- switch (type) {
293
- case EventType .createDirectory:
294
- // Issue 16003 means that a CREATE event for a directory can indicate
295
- // that the directory was moved and then re-created.
296
- // [_eventsBasedOnFileSystem] will handle this correctly by producing a
297
- // DELETE event followed by a CREATE event if the directory exists.
298
- return null ;
299
-
300
- case EventType .createFile:
301
- case EventType .delete:
302
- case EventType .modifyFile:
303
- return batch.firstWhere ((e) => e.type == type);
304
-
305
- // Guaranteed not present by `_sortEvents`.
306
- case EventType .moveFile:
307
- case EventType .moveDirectory:
308
- case EventType .modifyDirectory:
309
- throw StateError (type.name);
310
- }
262
+ final type = types.first;
263
+ return batch.firstWhere ((e) => e.type == type);
311
264
}
312
265
313
266
/// Returns one or more events that describe the change between the last known
0 commit comments