File tree Expand file tree Collapse file tree 4 files changed +48
-6
lines changed
lib/src/directory_watcher Expand file tree Collapse file tree 4 files changed +48
-6
lines changed Original file line number Diff line number Diff line change
1
+ ## 1.1.4-wip
2
+
3
+ - Improve handling of subdirectories on Linux: ignore ` PathNotFoundException `
4
+ due to subdirectory deletion during watch setup, instead of raising it on the
5
+ event stream.
6
+
1
7
## 1.1.3
2
8
3
9
- Improve handling of
6
12
events. But, the restart would sometimes silently fail. Now, it is more
7
13
reliable.
8
14
- Improving handling of directories that are created then immediately deleted on
9
- Windows. Previously, that could cause a ` PathNotfoundException ` to be thrown.
15
+ Windows. Previously, that could cause a ` PathNotFoundException ` to be thrown.
10
16
11
17
## 1.1.2
12
18
Original file line number Diff line number Diff line change @@ -136,10 +136,17 @@ class _LinuxDirectoryWatcher
136
136
// top-level clients such as barback as well, and could be implemented with
137
137
// a wrapper similar to how listening/canceling works now.
138
138
139
- // TODO(nweiz): Catch any errors here that indicate that the directory in
140
- // question doesn't exist and silently stop watching it instead of
141
- // propagating the errors.
142
- var stream = Directory (path).watch ();
139
+ var stream = Directory (path).watch ().transform (
140
+ StreamTransformer <FileSystemEvent , FileSystemEvent >.fromHandlers (
141
+ handleError: (error, st, sink) {
142
+ // Directory might no longer exist at the point where we try to
143
+ // start the watcher. Simply ignore this error and let the stream
144
+ // close.
145
+ if (error is ! PathNotFoundException ) {
146
+ sink.addError (error, st);
147
+ }
148
+ },
149
+ ));
143
150
_subdirStreams[path] = stream;
144
151
_nativeEvents.add (stream);
145
152
}
Original file line number Diff line number Diff line change 1
1
name : watcher
2
- version : 1.1.3
2
+ version : 1.1.4-wip
3
3
description : >-
4
4
A file system watcher. It monitors changes to contents of directories and
5
5
sends notifications when files have been added, removed, or modified.
Original file line number Diff line number Diff line change 1
1
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
+ import 'dart:io' as io;
5
+ import 'dart:isolate' ;
4
6
5
7
import 'package:test/test.dart' ;
8
+ import 'package:test_descriptor/test_descriptor.dart' as d;
6
9
import 'package:watcher/src/utils.dart' ;
7
10
8
11
import '../utils.dart' ;
@@ -340,5 +343,31 @@ void sharedTests() {
340
343
events.add (isRemoveEvent ('dir/sub' ));
341
344
await inAnyOrder (events);
342
345
});
346
+
347
+ test ('subdirectory watching is robust against races' , () async {
348
+ // Make sandboxPath accessible to child isolates created by Isolate.run.
349
+ final sandboxPath = d.sandbox;
350
+ final dirNames = [for (var i = 0 ; i < 50 ; i++ ) 'dir$i ' ];
351
+ await startWatcher ();
352
+
353
+ // Repeatedly create and delete subdirectories in attempt to trigger
354
+ // a race.
355
+ for (var i = 0 ; i < 10 ; i++ ) {
356
+ for (var dir in dirNames) {
357
+ createDir (dir);
358
+ }
359
+ await Isolate .run (() async {
360
+ await Future .wait ([
361
+ for (var dir in dirNames)
362
+ io.Directory ('$sandboxPath /$dir ' ).delete (),
363
+ ]);
364
+ });
365
+ }
366
+
367
+ writeFile ('a/b/c/d/file.txt' );
368
+ await inAnyOrder ([
369
+ isAddEvent ('a/b/c/d/file.txt' ),
370
+ ]);
371
+ });
343
372
});
344
373
}
You can’t perform that action at this time.
0 commit comments