Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(471)

Unified Diff: lib/src/directory_watcher/mac_os.dart

Issue 995623002: Fix bugs where events could be added after watchers were closed. (Closed) Base URL: git@github.com:dart-lang/watcher@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/directory_watcher/linux.dart ('k') | pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/directory_watcher/mac_os.dart
diff --git a/lib/src/directory_watcher/mac_os.dart b/lib/src/directory_watcher/mac_os.dart
index e3efa2dd64bc034aaeed4b1e9369c67171a036c1..e6f08dcb7751cb799d52c1925320155e1b0e563a 100644
--- a/lib/src/directory_watcher/mac_os.dart
+++ b/lib/src/directory_watcher/mac_os.dart
@@ -69,9 +69,9 @@ class _MacOSDirectoryWatcher implements ManuallyClosedDirectoryWatcher {
/// the directory to determine its initial state.
StreamSubscription<FileSystemEntity> _initialListSubscription;
- /// The subscription to the [Directory.list] call for listing the contents of
- /// a subdirectory that was moved into the watched directory.
- StreamSubscription<FileSystemEntity> _listSubscription;
+ /// The subscriptions to [Directory.list] calls for listing the contents of a
+ /// subdirectory that was moved into the watched directory.
+ final _listSubscriptions = new Set<StreamSubscription<FileSystemEntity>>();
/// The timer for tracking how long we wait for an initial batch of bogus
/// events (see issue 14373).
@@ -113,10 +113,14 @@ class _MacOSDirectoryWatcher implements ManuallyClosedDirectoryWatcher {
}
if (_watchSubscription != null) _watchSubscription.cancel();
if (_initialListSubscription != null) _initialListSubscription.cancel();
- if (_listSubscription != null) _listSubscription.cancel();
_watchSubscription = null;
_initialListSubscription = null;
- _listSubscription = null;
+
+ for (var subscription in _listSubscriptions) {
+ subscription.cancel();
+ }
+ _listSubscriptions.clear();
+
_eventsController.close();
}
@@ -191,8 +195,9 @@ class _MacOSDirectoryWatcher implements ManuallyClosedDirectoryWatcher {
if (_files.containsDir(path)) continue;
- var stream = Chain.track(new Directory(path).list(recursive: true));
- _listSubscription = stream.listen((entity) {
+ var subscription;
+ subscription = Chain.track(new Directory(path).list(recursive: true))
+ .listen((entity) {
if (entity is Directory) return;
if (_files.contains(path)) return;
@@ -203,7 +208,10 @@ class _MacOSDirectoryWatcher implements ManuallyClosedDirectoryWatcher {
print("[$_id] got error listing $relativePath: $e");
}
_emitError(e, stackTrace);
+ }, onDone: () {
+ _listSubscriptions.remove(subscription);
}, cancelOnError: true);
+ _listSubscriptions.add(subscription);
} else if (event is FileSystemModifyEvent) {
assert(!event.isDirectory);
_emitEvent(ChangeType.MODIFY, path);
« no previous file with comments | « lib/src/directory_watcher/linux.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698