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); |