Skip to content

Commit c77201f

Browse files
authored
Fix race with directory list on Windows (#2235)
1 parent c423dbe commit c77201f

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

pkgs/watcher/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
the file was created immediately before the watcher was created. Now, if the
1111
file exists when the watcher is created then this modify event is not sent.
1212
This matches the Linux native and polling (Windows) watchers.
13+
- Bug fix: with `DirectoryWatcher` on Windows, the last of a rapid sequence of
14+
modifications in a newly-created directory was sometimes dropped. Make it
15+
reliably report the last modification.
1316
- Bug fix: with `DirectoryWatcher` on Windows, a move over an existing file was
1417
reported incorrectly. For example, if `a` and `b` already exist, then `a` is
1518
moved onto `b`, it would be reported as three events: delete `a`, delete `b`,

pkgs/watcher/lib/src/directory_watcher/windows.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,16 @@ class _WindowsDirectoryWatcher
321321
types.contains(EventType.createFile)) {
322322
// Combine events of type [EventType.modifyFile] and
323323
// [EventType.createFile] to one event.
324-
type = EventType.createFile;
324+
325+
// The file can be already in `_files` if it's in a recently-created
326+
// directory, the directory list finds it and adds it. In that case a pair
327+
// of "create"+"modify" should be reported as "modify".
328+
//
329+
// Otherwise, it's a new file, "create"+"modify" should be reported as
330+
// "create".
331+
type = _files.contains(batch.first.path)
332+
? EventType.modifyFile
333+
: EventType.createFile;
325334
} else {
326335
// There are incompatible event types, check the filesystem.
327336
return null;

pkgs/watcher/test/directory_watcher/end_to_end_tests.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ void endToEndTests({required bool isNative}) {
5757
print('Ignoring expected failure for Linux native watcher.');
5858
return;
5959
}
60-
if (Platform.isWindows && isNative) {
61-
print('Ignoring expected failure for Windows native watcher.');
62-
return;
63-
}
6460

6561
// Write the file operations before the failure to a log, fail the test.
6662
final logTemp = Directory.systemTemp.createTempSync();

0 commit comments

Comments
 (0)