Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix race condition in PollingDirectoryWatcher #71

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 0.9.8

* Fix a race condition issue with the `PollingDirectoryWatcher`.
* Internal clean up, e.g. fix and enable lints.

# 0.9.7+12

* Catch `FileSystemException` during `existsSync()` on Windows.
Expand All @@ -20,15 +25,15 @@

# 0.9.7+7

* Updates to support Dart 2.0 core library changes (wave 2.2).
* Updates to support Dart 2.0 core library changes (wave 2.2).
See [issue 31847][sdk#31847] for details.

[sdk#31847]: https://github.com/dart-lang/sdk/issues/31847


# 0.9.7+6

* Internal changes only, namely removing dep on scheduled test.
* Internal changes only, namely removing dep on scheduled test.

# 0.9.7+5

Expand Down
37 changes: 21 additions & 16 deletions lib/src/directory_watcher/polling.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,29 +136,34 @@ class _PollingDirectoryWatcher
return;
}

final modified = await modificationTime(file);
try {
final modified = await modificationTime(file);

if (_events.isClosed) return;
if (_events.isClosed) return;

var lastModified = _lastModifieds[file];
var lastModified = _lastModifieds[file];

// If its modification time hasn't changed, assume the file is unchanged.
if (lastModified != null && lastModified == modified) {
// The file is still here.
_polledFiles.add(file);
return;
}
// If its modification time hasn't changed, assume the file is unchanged.
if (lastModified != null && lastModified == modified) {
// The file is still here.
_polledFiles.add(file);
return;
}

if (_events.isClosed) return;
if (_events.isClosed) return;

_lastModifieds[file] = modified;
_polledFiles.add(file);
_lastModifieds[file] = modified;
_polledFiles.add(file);

// Only notify if we're ready to emit events.
if (!isReady) return;
// Only notify if we're ready to emit events.
if (!isReady) return;

var type = lastModified == null ? ChangeType.ADD : ChangeType.MODIFY;
_events.add(WatchEvent(type, file));
var type = lastModified == null ? ChangeType.ADD : ChangeType.MODIFY;
_events.add(WatchEvent(type, file));
} on FileSystemException {
// Ignore as the file could have been removed since the poll.
// The `_completePoll` step will handle this situation.
}
}

/// After the directory listing is complete, this determines which files were
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: watcher
version: 0.9.8-dev
version: 0.9.8

description: >-
A file system watcher. It monitors changes to contents of directories and
Expand Down