@@ -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,40 @@ 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 ;
171-
172- changed.add (destination);
173- if (event.isDirectory) {
174- files.remove (destination);
175- 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);
166+ switch (event.type) {
167+ case EventType .moveFile:
168+ files.remove (event.path);
169+ dirs.remove (event.path);
170+ var destination = event.destination;
171+ if (destination != null ) {
172+ changed.add (destination);
173+ files.add (destination);
174+ dirs.remove (destination);
175+ }
176+
177+ case EventType .moveDirectory:
178+ files.remove (event.path);
179+ dirs.remove (event.path);
180+ var destination = event.destination;
181+ if (destination != null ) {
182+ changed.add (destination);
183+ files.remove (destination);
184+ dirs.add (destination);
185+ }
186+
187+ case EventType .delete:
188+ files.remove (event.path);
189+ dirs.remove (event.path);
190+
191+ case EventType .createDirectory:
192+ case EventType .modifyDirectory:
193+ files.remove (event.path);
194+ dirs.add (event.path);
195+
196+ case EventType .createFile:
197+ case EventType .modifyFile:
198+ files.add (event.path);
199+ dirs.remove (event.path);
189200 }
190201 }
191202
0 commit comments