@@ -8,6 +8,7 @@ import 'dart:io';
8
8
import 'package:async/async.dart' ;
9
9
10
10
import '../directory_watcher.dart' ;
11
+ import '../event.dart' ;
11
12
import '../path_set.dart' ;
12
13
import '../resubscribable.dart' ;
13
14
import '../utils.dart' ;
@@ -81,7 +82,7 @@ class _LinuxDirectoryWatcher
81
82
})));
82
83
83
84
// 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 ();
85
86
_listen (innerStream, _onBatch,
86
87
onError: (Object error, StackTrace stackTrace) {
87
88
// Guarantee that ready always completes.
@@ -145,7 +146,7 @@ class _LinuxDirectoryWatcher
145
146
}
146
147
147
148
/// The callback that's run when a batch of changes comes in.
148
- void _onBatch (List <FileSystemEvent > batch) {
149
+ void _onBatch (List <Event > batch) {
149
150
var files = < String > {};
150
151
var dirs = < String > {};
151
152
var changed = < String > {};
@@ -162,30 +163,40 @@ class _LinuxDirectoryWatcher
162
163
163
164
changed.add (event.path);
164
165
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);
189
200
}
190
201
}
191
202
0 commit comments