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

Unified Diff: pkg/watcher/lib/src/directory_watcher.dart

Issue 22999008: Handle watching a non-existent directory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise. Created 7 years, 4 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 | « no previous file | pkg/watcher/lib/src/utils.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « no previous file | pkg/watcher/lib/src/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698