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

FileSystemEvent.isDirectory returns wrong value when directory itself is deleted #35032

Closed
sgrekhov opened this issue Nov 2, 2018 · 6 comments
Assignees
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@sgrekhov
Copy link
Contributor

sgrekhov commented Nov 2, 2018

Create a durectory, watch it, then delete and see fired FileSystemEvent. Example

import "dart:io";
main() {
  Directory sandbox = new Directory(Directory.systemTemp.path + Platform.pathSeparator + "test-dir");
  sandbox.createSync();
  Directory dir = sandbox.createTempSync();

  dir.watch().listen((FileSystemEvent event) {
      print(event);
      print(event.isDirectory);
  });
  dir.deleteSync();

  new Future.delayed(new Duration(seconds: 1)).then((_) {
    sandbox.delete(recursive: true);
  });
}

Output is

FileSystemDeleteEvent('/tmp/test-dir/FXJVOX')
false

Here we delete a directory. Why FileSystemDeleteEvent.isDirectory is false?

Dart VM version: 2.1.0-dev.8.0 (Unknown timestamp) on "linux_x64"

@dgrove dgrove added library-io area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. labels Nov 5, 2018
@sortie sortie added P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Jan 22, 2019
@zichangg zichangg self-assigned this Oct 17, 2019
@zichangg
Copy link
Contributor

This is because underlying inotify doesn't set the isDir bit. FileSystemDeleteEvent.isDirectory comes directly from IN_ISDIR bit.
Besides, from dart api page, isDirectory says,

In particular, it will always be false for delete events.

@zichangg
Copy link
Contributor

But Mac OS does report isDirectory as true if running the sample program. I think this description is not accurate enough.

@sgrekhov
Copy link
Contributor Author

sgrekhov commented Oct 18, 2019

Just retested on Linux (Ubuntu 18).
Dart VM version: 2.6.0-dev.7.0 (Unknown timestamp) on "linux_x64". isDirectory is false

FileSystemDeleteEvent('/tmp/test-dir/FVEEZH')
false

@zichangg
Copy link
Contributor

Hi @sgrekhov

I tried to make changes to be consistent with our api doc.

But 2 co19_2 tests complained (https://logs.chromium.org/logs/dart/buildbucket/cr-buildbucket.appspot.com/8888003642068032448/+/steps/test_results/0/logs/new_test_failures__logs_/0).

I think they should be changed to be synced with api page.

@sgrekhov
Copy link
Contributor Author

@zichangg created dart-lang/co19#532 to change co19 tests

dart-bot pushed a commit that referenced this issue Feb 24, 2020
According to the `FileSystemEvent` api page, isDirectory should always be false for delete events.

Bug: #35032
Change-Id: Ic277aa366db09c016979350d7369e004f9a8a152
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136405
Commit-Queue: Zichang Guo <zichangguo@google.com>
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Jonas Termansen <sortie@google.com>
@zichangg
Copy link
Contributor

@sgrekhov
The change has been landed and I approved the test failures. Can you update the tests accordingly?

There are 2 tests to be updated:
io/FileSystemDeleteEvent/isDirectory_A01_t03.dart
io/FileSystemDeleteEvent/isDirectory_A01_t01.dart

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants