diff --git a/pkgs/watcher/CHANGELOG.md b/pkgs/watcher/CHANGELOG.md index 686126dc1..d1e837596 100644 --- a/pkgs/watcher/CHANGELOG.md +++ b/pkgs/watcher/CHANGELOG.md @@ -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 diff --git a/pkgs/watcher/lib/src/directory_watcher/windows.dart b/pkgs/watcher/lib/src/directory_watcher/windows.dart index 87eca0f2f..428ceb069 100644 --- a/pkgs/watcher/lib/src/directory_watcher/windows.dart +++ b/pkgs/watcher/lib/src/directory_watcher/windows.dart @@ -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; @@ -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. @@ -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 @@ -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; } @@ -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'); } diff --git a/pkgs/watcher/test/directory_watcher/shared.dart b/pkgs/watcher/test/directory_watcher/shared.dart index 10541cf8d..9a26a47a1 100644 --- a/pkgs/watcher/test/directory_watcher/shared.dart +++ b/pkgs/watcher/test/directory_watcher/shared.dart @@ -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') }); }); @@ -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 {