Index: pkg/watcher/lib/src/directory_watcher.dart |
diff --git a/pkg/watcher/lib/src/directory_watcher.dart b/pkg/watcher/lib/src/directory_watcher.dart |
index c5dd9db606bb589bd69fc411a16d428a0de7c6aa..eb948f57cd5da7bb63884e1bbc63f74375f67eb4 100644 |
--- a/pkg/watcher/lib/src/directory_watcher.dart |
+++ b/pkg/watcher/lib/src/directory_watcher.dart |
@@ -11,6 +11,7 @@ import 'package:crypto/crypto.dart'; |
import 'async_queue.dart'; |
import 'stat.dart'; |
+import 'utils.dart'; |
import 'watch_event.dart'; |
/// Watches the contents of a directory and emits [WatchEvent]s when something |
@@ -118,19 +119,33 @@ class DirectoryWatcher { |
_filesToProcess.clear(); |
_polledFiles.clear(); |
+ endListing() { |
+ assert(_state != _WatchState.UNSUBSCRIBED); |
+ _listSubscription = null; |
+ |
+ // Null tells the queue consumer that we're done listing. |
+ _filesToProcess.add(null); |
+ } |
+ |
var stream = new Directory(directory).list(recursive: true); |
_listSubscription = stream.listen((entity) { |
assert(_state != _WatchState.UNSUBSCRIBED); |
if (entity is! File) return; |
_filesToProcess.add(entity.path); |
- }, onDone: () { |
- assert(_state != _WatchState.UNSUBSCRIBED); |
- _listSubscription = null; |
+ }, onError: (error) { |
+ if (isDirectoryNotFoundException(error)) { |
+ // If the directory doesn't exist, we end the listing normally, which |
+ // has the desired effect of marking all files that were in the |
+ // directory as being removed. |
+ endListing(); |
+ return; |
+ } |
- // Null tells the queue consumer that we're done listing. |
- _filesToProcess.add(null); |
- }); |
+ // It's some unknown error. Pipe it over to the event stream so we don't |
+ // take down the whole isolate. |
+ _events.addError(error); |
+ }, onDone: endListing); |
} |
/// Processes [file] to determine if it has been modified since the last |