@@ -8,6 +8,7 @@ import 'dart:io';
88import 'package:async/async.dart' ;
99
1010import '../directory_watcher.dart' ;
11+ import '../event.dart' ;
1112import '../path_set.dart' ;
1213import '../resubscribable.dart' ;
1314import '../utils.dart' ;
@@ -81,7 +82,7 @@ class _LinuxDirectoryWatcher
8182 })));
8283
8384 // Batch the inotify changes together so that we can dedup events.
84- var innerStream = _nativeEvents.stream.batchEvents ();
85+ var innerStream = _nativeEvents.stream.map ( Event . new ). batchEvents ();
8586 _listen (innerStream, _onBatch,
8687 onError: (Object error, StackTrace stackTrace) {
8788 // Guarantee that ready always completes.
@@ -145,7 +146,7 @@ class _LinuxDirectoryWatcher
145146 }
146147
147148 /// The callback that's run when a batch of changes comes in.
148- void _onBatch (List <FileSystemEvent > batch) {
149+ void _onBatch (List <Event > batch) {
149150 var files = < String > {};
150151 var dirs = < String > {};
151152 var changed = < String > {};
@@ -162,30 +163,33 @@ class _LinuxDirectoryWatcher
162163
163164 changed.add (event.path);
164165
165- if (event is FileSystemMoveEvent ) {
166- files.remove (event.path);
167- dirs.remove (event.path);
168-
169- var destination = event.destination;
170- if (destination == null ) continue ;
166+ switch (event.type) {
167+ case EventType .moveFile:
168+ files.remove (event.path);
169+ var destination = event.destination! ;
170+ changed.add (destination);
171+ files.add (destination);
172+ dirs.remove (destination);
171173
172- changed.add (destination);
173- if (event.isDirectory) {
174+ case EventType .moveDirectory:
175+ dirs.remove (event.path);
176+ var destination = event.destination! ;
174177 files.remove (destination);
175178 dirs.add (destination);
176- } else {
177- files.add (destination);
178- dirs.remove (destination);
179- }
180- } else if (event is FileSystemDeleteEvent ) {
181- files.remove (event.path);
182- dirs.remove (event.path);
183- } else if (event.isDirectory) {
184- files.remove (event.path);
185- dirs.add (event.path);
186- } else {
187- files.add (event.path);
188- dirs.remove (event.path);
179+
180+ case EventType .delete:
181+ files.remove (event.path);
182+ dirs.remove (event.path);
183+
184+ case EventType .createDirectory:
185+ case EventType .modifyDirectory:
186+ files.remove (event.path);
187+ dirs.add (event.path);
188+
189+ case EventType .createFile:
190+ case EventType .modifyFile:
191+ files.add (event.path);
192+ dirs.remove (event.path);
189193 }
190194 }
191195
0 commit comments