Skip to content

Commit 6d7cbf4

Browse files
committed
Use the MacOS directory watcher on Windows too.
1 parent a654530 commit 6d7cbf4

31 files changed

+860
-1279
lines changed

pkgs/watcher/benchmark/path_set.dart

Lines changed: 0 additions & 158 deletions
This file was deleted.

pkgs/watcher/lib/src/directory_watcher.dart

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@ import 'directory_watcher/windows_resubscribable_watcher.dart';
1515
///
1616
/// On Windows, the underlying SDK `Directory.watch` fails if too many events
1717
/// are received while Dart is busy, for example during a long-running
18-
/// synchronous operation. When this happens, some events are dropped.
19-
/// `DirectoryWatcher` restarts the watch and sends a `FileSystemException` with
20-
/// the message "Directory watcher closed unexpectedly" on the event stream. The
21-
/// code using the watcher needs to do additional work to account for the
22-
/// dropped events, for example by recomputing interesting files from scratch.
23-
/// By default, the watcher is started in a separate isolate to make this less
24-
/// likely. Pass `runInIsolateOnWindows = false` to not launch an isolate.
18+
/// synchronous operation. When this happens, watching is re-established and a
19+
/// "modify" event is emitted for any file still present that lost tracking, in
20+
/// case it changed. By default, the watcher is started in a separate isolate to
21+
/// make this less likely. Pass `runInIsolateOnWindows = false` to not launch an
22+
/// isolate.
2523
///
2624
/// On Linux, the underlying SDK `Directory.watch` fails if the system limit on
2725
/// watchers has been reached. If this happens the SDK exception is thrown, it

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import 'dart:io';
77

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

10-
import '../utils.dart';
11-
1210
extension DirectoryRobustRecursiveListing on Directory {
1311
/// Lists the given directory recursively ignoring not-found or access errors.
1412
///
@@ -233,3 +231,18 @@ const _errorInvalidName = 123;
233231
const _errorBadPathName = 161;
234232
const _errorAlreadyExists = 183;
235233
const _errorFilenameExedRange = 206;
234+
235+
extension IgnoringError<T> on Stream<T> {
236+
/// Ignore all errors of type [E] emitted by the given stream.
237+
///
238+
/// Everything else gets forwarded through as-is.
239+
Stream<T> ignoring<E>() {
240+
return transform(StreamTransformer<T, T>.fromHandlers(
241+
handleError: (error, st, sink) {
242+
if (error is! E) {
243+
sink.addError(error, st);
244+
}
245+
},
246+
));
247+
}
248+
}

pkgs/watcher/lib/src/directory_watcher/macos/event_tree.dart renamed to pkgs/watcher/lib/src/directory_watcher/event_tree.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import '../../unix_paths.dart';
5+
import '../paths.dart';
66

77
/// Tree of event paths relative to the watched path.
88
///

pkgs/watcher/lib/src/directory_watcher/linux/native_watch.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import 'dart:async';
66
import 'dart:io';
77

88
import '../../event.dart';
9-
import '../../unix_paths.dart';
10-
import '../../utils.dart';
9+
import '../../event_batching.dart';
10+
import '../../paths.dart';
11+
import '../../testing.dart';
1112

1213
/// Watches a directory with the native Linux watcher.
1314
///
@@ -88,7 +89,7 @@ class NativeWatch {
8889
logForTesting?.call('NativeWatch(),$watchedDirectory');
8990
_subscription = watchedDirectory
9091
.watch()
91-
.batchAndConvertEvents()
92+
.batchNearbyMicrotasksAndConvertEvents()
9293
.listen(_onData, onError: _onError);
9394
}
9495

pkgs/watcher/lib/src/directory_watcher/linux/watch_tree.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import 'dart:io';
66

77
import '../../event.dart';
8-
import '../../unix_paths.dart';
9-
import '../../utils.dart';
8+
import '../../paths.dart';
9+
import '../../testing.dart';
1010
import '../../watch_event.dart';
1111
import 'native_watch.dart';
1212

pkgs/watcher/lib/src/directory_watcher/linux/watch_tree_root.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
import 'dart:async';
66

7-
import '../../unix_paths.dart';
8-
import '../../utils.dart';
7+
import '../../paths.dart';
8+
import '../../testing.dart';
99
import '../../watch_event.dart';
1010
import 'watch_tree.dart';
1111

pkgs/watcher/lib/src/directory_watcher/macos/directory_tree.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
import 'dart:io';
66

7-
import '../../unix_paths.dart';
8-
import '../../utils.dart';
7+
import '../../paths.dart';
8+
import '../../testing.dart';
99
import '../../watch_event.dart';
10-
import 'event_tree.dart';
10+
import '../event_tree.dart';
1111

1212
/// MacOS directory tree.
1313
///

0 commit comments

Comments
 (0)