Skip to content
Draft
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
3 changes: 3 additions & 0 deletions pkgs/watcher/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
the file was created immediately before the watcher was created. Now, if the
file exists when the watcher is created then this modify event is not sent.
This matches the Linux native and polling (Windows) watchers.
- Bug fix: fix a spurious modify event with `DirectoryWatcher` on Windows that
was reported when a file or directory was renamed then another file or
directory was immediately renamed to its old name.

## 1.1.4

Expand Down
21 changes: 11 additions & 10 deletions pkgs/watcher/lib/src/directory_watcher/windows.dart
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,16 @@ class _WindowsDirectoryWatcher

for (var event in batch) {
if (event is FileSystemMoveEvent) {
addEvent(
event.path, FileSystemDeleteEvent(event.path, event.isDirectory));
var destination = event.destination;
if (destination != null) {
addEvent(destination, event);
addEvent(destination,
FileSystemCreateEvent(event.path, event.isDirectory));
}
} else {
addEvent(event.path, event);
}
addEvent(event.path, event);
}

return eventsForPaths;
Expand All @@ -280,6 +284,9 @@ class _WindowsDirectoryWatcher
/// Returns the canonical event from a batch of events on the same path, if
/// one exists.
///
/// The batch must be an output of [_sortEvents] which guarantees it contains
/// no [FileSystemMoveEvent]s.
///
/// If [batch] doesn't contain any contradictory events (e.g. DELETE and
/// CREATE, or events with different values for `isDirectory`), this returns a
/// single event that describes what happened to the path in question.
Expand All @@ -306,9 +313,7 @@ class _WindowsDirectoryWatcher
// (respectively) that will be contradictory.
if (event is FileSystemModifyEvent) continue;
assert(
event is FileSystemCreateEvent ||
event is FileSystemDeleteEvent ||
event is FileSystemMoveEvent,
event is FileSystemCreateEvent || event is FileSystemDeleteEvent,
);

// If we previously thought this was a MODIFY, we now consider it to be a
Expand All @@ -320,9 +325,7 @@ class _WindowsDirectoryWatcher

// A CREATE event contradicts a REMOVE event and vice versa.
assert(
type == FileSystemEvent.create ||
type == FileSystemEvent.delete ||
type == FileSystemEvent.move,
type == FileSystemEvent.create || type == FileSystemEvent.delete,
);
if (type != event.type) return null;
}
Expand All @@ -334,8 +337,6 @@ class _WindowsDirectoryWatcher
return FileSystemDeleteEvent(batch.first.path, isDir);
case FileSystemEvent.modify:
return FileSystemModifyEvent(batch.first.path, isDir, false);
case FileSystemEvent.move:
return null;
default:
throw StateError('unreachable');
}
Expand Down
4 changes: 0 additions & 4 deletions pkgs/watcher/test/directory_watcher/shared.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ void sharedTests() {

renameFile('from.txt', 'to.txt');
await inAnyOrder([isRemoveEvent('from.txt'), isModifyEvent('to.txt')]);
}, onPlatform: {
'windows': const Skip('https://github.com/dart-lang/watcher/issues/125')
});
});

Expand Down Expand Up @@ -280,8 +278,6 @@ void sharedTests() {
isRemoveEvent('old'),
isAddEvent('new')
]);
}, onPlatform: {
'windows': const Skip('https://github.com/dart-lang/watcher/issues/21')
});

test('emits events for many nested files added at once', () async {
Expand Down
Loading