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

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: 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/test/directory_watcher_test.dart » ('j') | pkg/watcher/test/utils.dart » ('J')
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..6fa49a9aad0e9a12e1703b7f5f2a45e5bc17d456 100644
--- a/pkg/watcher/lib/src/directory_watcher.dart
+++ b/pkg/watcher/lib/src/directory_watcher.dart
@@ -118,19 +118,27 @@ 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;
-
- // Null tells the queue consumer that we're done listing.
- _filesToProcess.add(null);
- });
+ }, onError: (error) {
+ // If an error occurred during the listing, it usually means the
nweiz 2013/08/14 19:43:11 Check if the error is the error we expect from the
Bob Nystrom 2013/08/16 21:40:19 Done. Instead of printing it, I pipe the error to
+ // 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();
+ }, onDone: endListing);
}
/// Processes [file] to determine if it has been modified since the last
« no previous file with comments | « no previous file | pkg/watcher/test/directory_watcher_test.dart » ('j') | pkg/watcher/test/utils.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698