Skip to content

Commit 1260b09

Browse files
committed
Remove test skip on Windows, fix the implementation.
1 parent 6866f9b commit 1260b09

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

pkgs/watcher/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
the file was created immediately before the watcher was created. Now, if the
55
file exists when the watcher is created then this modify event is not sent.
66
This matches the Linux native and polling (Windows) watchers.
7+
- Bug fix: fix a spurious modify event with `DirectoryWatcher` on Windows that
8+
was reported when a file or directory was renamed then another file or
9+
directory was immediately renamed to its old name.
710

811
## 1.1.4
912

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,16 @@ class _WindowsDirectoryWatcher
266266

267267
for (var event in batch) {
268268
if (event is FileSystemMoveEvent) {
269+
addEvent(
270+
event.path, FileSystemDeleteEvent(event.path, event.isDirectory));
269271
var destination = event.destination;
270272
if (destination != null) {
271-
addEvent(destination, event);
273+
addEvent(destination,
274+
FileSystemCreateEvent(event.path, event.isDirectory));
272275
}
276+
} else {
277+
addEvent(event.path, event);
273278
}
274-
addEvent(event.path, event);
275279
}
276280

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

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

321326
// A CREATE event contradicts a REMOVE event and vice versa.
322327
assert(
323-
type == FileSystemEvent.create ||
324-
type == FileSystemEvent.delete ||
325-
type == FileSystemEvent.move,
328+
type == FileSystemEvent.create || type == FileSystemEvent.delete,
326329
);
327330
if (type != event.type) return null;
328331
}
@@ -334,8 +337,6 @@ class _WindowsDirectoryWatcher
334337
return FileSystemDeleteEvent(batch.first.path, isDir);
335338
case FileSystemEvent.modify:
336339
return FileSystemModifyEvent(batch.first.path, isDir, false);
337-
case FileSystemEvent.move:
338-
return null;
339340
default:
340341
throw StateError('unreachable');
341342
}

pkgs/watcher/test/directory_watcher/shared.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@ void sharedTests() {
137137

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

@@ -280,8 +278,6 @@ void sharedTests() {
280278
isRemoveEvent('old'),
281279
isAddEvent('new')
282280
]);
283-
}, onPlatform: {
284-
'windows': const Skip('https://github.com/dart-lang/watcher/issues/21')
285281
});
286282

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

0 commit comments

Comments
 (0)