sdk
sdk copied to clipboard
Windows Directory.watch continues incorrectly after directory move
Related to https://github.com/dart-lang/sdk/issues/62193
If the watched directory is moved, no indication is given on the event stream; it continues to emit events about the new path, but with wrong paths still rooted in the old path.
import 'dart:io';
Future<void> main() async {
final temp = Directory.systemTemp.createTempSync();
final dir = Directory('${temp.path}\\dir')..createSync();
dir.watch(recursive: true).listen(
(e) => print('data $e'),
onError: (e, s) => print('onError: $e $s'),
onDone: () => print('onDone'));
await Future.delayed(Duration(milliseconds: 200));
dir.renameSync('${temp.path}\\newdir');
for (var i = 0; i != 5; ++i) {
File('${temp.path}\\newdir\\f$i').createSync();
await Future.delayed(Duration(milliseconds: 200));
}
}
prints paths with "dir" instead of "newdir".
package:watcher already works around this by watching the parent directory of the watched directory in order to detect moves+deletes.