Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing events for files with directory prefix #84

Merged
merged 2 commits into from
Apr 16, 2020
Merged
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 0.9.7+15-dev

* Fix a bug on Mac where modifying a directory with a path exactly matching a
prefix of a modified file would suppress change events for that file.

# 0.9.7+14

* Prepare for breaking change in SDK where modified times for not found files
Expand Down
4 changes: 3 additions & 1 deletion lib/src/directory_watcher/mac_os.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import 'dart:async';
import 'dart:io';

import 'package:path/path.dart' as p;

import '../directory_watcher.dart';
import '../constructable_file_system_event.dart';
import '../path_set.dart';
Expand Down Expand Up @@ -196,7 +198,7 @@ class _MacOSDirectoryWatcher
}));

bool isInModifiedDirectory(String path) =>
directories.any((dir) => path != dir && path.startsWith(dir));
directories.any((dir) => path != dir && p.isWithin(dir, path));

void addEvent(String path, FileSystemEvent event) {
if (isInModifiedDirectory(path)) return;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/directory_watcher/windows.dart
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class _WindowsDirectoryWatcher
}));

bool isInModifiedDirectory(String path) =>
directories.any((dir) => path != dir && path.startsWith(dir));
directories.any((dir) => path != dir && p.isWithin(dir, path));

void addEvent(String path, FileSystemEvent event) {
if (isInModifiedDirectory(path)) return;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: watcher
version: 0.9.7+14
version: 0.9.7+15-dev

description: >-
A file system watcher. It monitors changes to contents of directories and
Expand Down
11 changes: 11 additions & 0 deletions test/directory_watcher/mac_os_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,15 @@ void main() {
(i, j, k) => isModifyEvent('dir/sub/sub-$i/sub-$j/file-$k.txt')));
});
});
test('does not suppress files with the same prefix as a directory', () async {
// Regression test for https://github.com/dart-lang/watcher/issues/83
writeFile('some_name.txt');

await startWatcher();

writeFile('some_name/some_name.txt');
deleteFile('some_name.txt');

await expectRemoveEvent('some_name.txt');
});
}