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

Unified Diff: lib/src/file_watcher/polling.dart

Issue 1228703007: Fix a race condition in file watcher. (Closed) Base URL: git@github.com:dart-lang/watcher@master
Patch Set: Created 5 years, 5 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 | « lib/src/file_watcher/native.dart ('k') | pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/file_watcher/polling.dart
diff --git a/lib/src/file_watcher/polling.dart b/lib/src/file_watcher/polling.dart
index a44f80cdb4654d78277845a8fbbee5de416d9b33..3480ae29eb78094e0b9f86a6d41022cab7039c54 100644
--- a/lib/src/file_watcher/polling.dart
+++ b/lib/src/file_watcher/polling.dart
@@ -51,7 +51,10 @@ class _PollingFileWatcher implements FileWatcher, ManuallyClosedWatcher {
// We don't mark the file as removed if this is the first poll (indicated by
// [_lastModified] being null). Instead, below we forward the dart:io error
// that comes from trying to read the mtime below.
- if (_lastModified != null && !await new File(path).exists()) {
+ var pathExists = await new File(path).exists();
+ if (_eventsController.isClosed) return;
+
+ if (_lastModified != null && !pathExists) {
_eventsController.add(new WatchEvent(ChangeType.REMOVE, path));
close();
return;
@@ -59,14 +62,17 @@ class _PollingFileWatcher implements FileWatcher, ManuallyClosedWatcher {
var modified;
try {
- modified = await getModificationTime(path);
+ try {
+ modified = await getModificationTime(path);
+ } finally {
Bob Nystrom 2015/07/17 15:58:22 Can you just add this to the outer try?
nweiz 2015/07/17 20:42:18 No, it needs to happen before "_eventsController.a
+ if (_eventsController.isClosed) return;
+ }
} on FileSystemException catch (error, stackTrace) {
_eventsController.addError(error, stackTrace);
close();
return;
}
- if (_eventsController.isClosed) return;
if (_lastModified == modified) return;
if (_lastModified == null) {
« no previous file with comments | « lib/src/file_watcher/native.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698