Ignore directory modify events on Mac. (#2296)
diff --git a/pkgs/watcher/CHANGELOG.md b/pkgs/watcher/CHANGELOG.md index 0d64856..ad9548d 100644 --- a/pkgs/watcher/CHANGELOG.md +++ b/pkgs/watcher/CHANGELOG.md
@@ -1,4 +1,4 @@ -## 1.2.1-wip +## 1.2.1 - Bug fix: versions before 1.2.0 would allow and ignore a trailing path separator passed to `DirectoryWatcher` or `FileWatcher` constructors, restore @@ -6,6 +6,9 @@ - In paths passed to `DirectoryWatcher` or `FileWatcher` constructors, remove multiple adjacent separators and `.` and `..`, so they will not be returned in events. +- Bug fix: on Mac, stop issuing `assert(false)` when a `modifyDirectory` event + is ignored, so the unused events are silently ignored instead of throwing in + debug builds. ## 1.2.0
diff --git a/pkgs/watcher/lib/src/event.dart b/pkgs/watcher/lib/src/event.dart index 4e0fad8..e2e6e2f 100644 --- a/pkgs/watcher/lib/src/event.dart +++ b/pkgs/watcher/lib/src/event.dart
@@ -23,19 +23,10 @@ /// Returns `null` if [event] should be ignored on this platform. static Event? checkAndConvert(FileSystemEvent event) { var result = Event._(event); - if (Platform.isMacOS) { - if (result.type.isNeverReceivedOnMacOS) { - assert(false); - return null; - } - } else if (Platform.isWindows) { - if (result.type.isIgnoredOnWindows) { - return null; - } - } else if (Platform.isLinux) { - if (result.type.isIgnoredOnLinux) { - return null; - } + if (result.type.isIgnored) return null; + if (Platform.isMacOS && result.type.isNeverReceivedOnMacOS) { + assert(false); + return null; } return result; } @@ -126,22 +117,19 @@ bool get isNeverReceivedOnMacOS { // See https://github.com/dart-lang/sdk/issues/14806. - if (this == moveFile || this == moveDirectory) { - return true; - } - if (this == modifyDirectory) return true; - return false; + return this == moveFile || this == moveDirectory; } - bool get isIgnoredOnWindows { - // Ignore [modifyDirectory] because it's always accompanied by either - // [createDirectory] or [deleteDirectory]. - return this == modifyDirectory; - } - - bool get isIgnoredOnLinux { - // Ignore [modifyDirectory], it arrives when the directory attributes - // changed which is not useful. + bool get isIgnored { + // On Windows, `modifyDirectory` is always accompanied by either + // `createDirectory` or `deleteDirectory`, so it's not needed. + // + // On Linux, `modifyDirectory` means the directory attributes such as + // permissions changed, so it's not a useful event. + // + // `modifyDirectory` on Mac also relates to directory attributes but is + // harder to repro, using `unzip` works. It's not a useful event. See + // https://github.com/dart-lang/tools/issues/2283. return this == modifyDirectory; } }
diff --git a/pkgs/watcher/pubspec.yaml b/pkgs/watcher/pubspec.yaml index 5faf63b..7089293 100644 --- a/pkgs/watcher/pubspec.yaml +++ b/pkgs/watcher/pubspec.yaml
@@ -1,5 +1,5 @@ name: watcher -version: 1.2.1-wip +version: 1.2.1 description: >- A file system watcher. It monitors changes to contents of directories and sends notifications when files have been added, removed, or modified.