Skip to content

Incorrect watcher reporting following directory rename on Linux #61861

@davidmorgan

Description

@davidmorgan

@mraleph

Related to #61860 but this time the directory that gets renamed is a parent of the directory being watched.

import 'dart:io';

void main() async {
  final d = Directory.systemTemp.createTempSync();
  final d2 = Directory('${d.path}/2')..createSync();
  final d3 = Directory('${d2.path}/3')..createSync();
  d3.watch().listen(
      (e) => print('for ${d3.path}: $e'),
      onDone: () => print('closed ${d3.path}'));
  File('${d3.path}/f').createSync();
  final newName = '${d2.path}-renamed/3';
  d2.rename('${d2.path}-renamed');
  Directory(newName).watch().listen(
      (e) => print('for $newName: $e'),
      onDone: () => print('closed ${newName}'));

  File('$newName/g').createSync();

  await Future.delayed(Duration(seconds: 1));

  File('$newName/h').createSync();
}

prints

for /tmp/IJKIQC/2/3: FileSystemCreateEvent('/tmp/IJKIQC/2/3/f', isDirectory=false)
for /tmp/IJKIQC/2-renamed/3: FileSystemCreateEvent('/tmp/IJKIQC/2/3/f', isDirectory=false)
for /tmp/IJKIQC/2/3: FileSystemCreateEvent('/tmp/IJKIQC/2/3/g', isDirectory=false)
for /tmp/IJKIQC/2-renamed/3: FileSystemCreateEvent('/tmp/IJKIQC/2/3/g', isDirectory=false)
for /tmp/IJKIQC/2/3: FileSystemCreateEvent('/tmp/IJKIQC/2/3/h', isDirectory=false)
for /tmp/IJKIQC/2-renamed/3: FileSystemCreateEvent('/tmp/IJKIQC/2/3/h', isDirectory=false)

this one seems like an actual bug: what seems to be happening is that the watch on the pre-rename watcher stays open, and the watch on the post-rename path never receives events with the new name, it receives new events much later under the old path.

Metadata

Metadata

Assignees

Labels

P3A lower priority bug or feature requestarea-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.library-iotriagedIssue has been triaged by sub team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions