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

Side by Side Diff: pkg/watcher/lib/src/directory_watcher.dart

Issue 23085006: Fix error handling in watcher. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Cancel subscription after error too. 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library watcher.directory_watcher; 5 library watcher.directory_watcher;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'package:crypto/crypto.dart'; 10 import 'package:crypto/crypto.dart';
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 _filesToProcess.add(null); 127 _filesToProcess.add(null);
128 } 128 }
129 129
130 var stream = new Directory(directory).list(recursive: true); 130 var stream = new Directory(directory).list(recursive: true);
131 _listSubscription = stream.listen((entity) { 131 _listSubscription = stream.listen((entity) {
132 assert(_state != _WatchState.UNSUBSCRIBED); 132 assert(_state != _WatchState.UNSUBSCRIBED);
133 133
134 if (entity is! File) return; 134 if (entity is! File) return;
135 _filesToProcess.add(entity.path); 135 _filesToProcess.add(entity.path);
136 }, onError: (error) { 136 }, onError: (error) {
137 if (isDirectoryNotFoundException(error)) { 137 if (!isDirectoryNotFoundException(error)) {
138 // If the directory doesn't exist, we end the listing normally, which 138 // It's some unknown error. Pipe it over to the event stream so the
139 // has the desired effect of marking all files that were in the 139 // user can see it.
140 // directory as being removed. 140 _events.addError(error);
141 endListing();
142 return;
143 } 141 }
144 142
145 // It's some unknown error. Pipe it over to the event stream so we don't 143 // When an error occurs, we end the listing normally, which has the
146 // take down the whole isolate. 144 // desired effect of marking all files that were in the directory as
147 _events.addError(error); 145 // being removed.
148 }, onDone: endListing); 146 endListing();
147 }, onDone: endListing, cancelOnError: true);
149 } 148 }
150 149
151 /// Processes [file] to determine if it has been modified since the last 150 /// Processes [file] to determine if it has been modified since the last
152 /// time it was scanned. 151 /// time it was scanned.
153 Future _processFile(String file) { 152 Future _processFile(String file) {
154 assert(_state != _WatchState.UNSUBSCRIBED); 153 assert(_state != _WatchState.UNSUBSCRIBED);
155 154
156 // `null` is the sentinel which means the directory listing is complete. 155 // `null` is the sentinel which means the directory listing is complete.
157 if (file == null) return _completePoll(); 156 if (file == null) return _completePoll();
158 157
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 272
274 class _FileStatus { 273 class _FileStatus {
275 /// The last time the file was modified. 274 /// The last time the file was modified.
276 DateTime modified; 275 DateTime modified;
277 276
278 /// The SHA-1 hash of the contents of the file. 277 /// The SHA-1 hash of the contents of the file.
279 List<int> hash; 278 List<int> hash;
280 279
281 _FileStatus(this.modified, this.hash); 280 _FileStatus(this.modified, this.hash);
282 } 281 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698