Skip to content

Commit 57a88fc

Browse files
zichanggcommit-bot@chromium.org
authored andcommitted
Reland "[io] exclude links from isDirectory()"
This is a reland of 49d743f Original change's description: > [io] exclude links from isDirectory() > > isDirectory() should not return true for links. > > Bug: #35102 > Change-Id: I737345a581d6a50d7bccab0dbc10f1a31a57e219 > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/121900 > Commit-Queue: Zichang Guo <zichangguo@google.com> > Reviewed-by: Siva Annamalai <asiva@google.com> Bug: #35102 Change-Id: Ifa4317ec77172d3f196f6f75307b940d614e27bb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/122028 Reviewed-by: Siva Annamalai <asiva@google.com> Commit-Queue: Zichang Guo <zichangguo@google.com>
1 parent 6c36630 commit 57a88fc

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

sdk/lib/_internal/vm/bin/file_patch.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,9 @@ class _FileSystemWatcher {
217217
bool getIsDir(event) {
218218
if (Platform.isWindows) {
219219
// Windows does not get 'isDir' as part of the event.
220-
return FileSystemEntity.isDirectorySync(getPath(event));
220+
// Links should also be skipped.
221+
return FileSystemEntity.isDirectorySync(getPath(event)) &&
222+
!FileSystemEntity.isLinkSync(getPath(event));
221223
}
222224
return (event[0] & FileSystemEvent._isDir) != 0;
223225
}

sdk_nnbd/lib/_internal/vm/bin/file_patch.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,9 @@ class _FileSystemWatcher {
219219
bool getIsDir(event) {
220220
if (Platform.isWindows) {
221221
// Windows does not get 'isDir' as part of the event.
222-
return FileSystemEntity.isDirectorySync(getPath(event));
222+
// Links should also be skipped.
223+
return FileSystemEntity.isDirectorySync(getPath(event)) &&
224+
!FileSystemEntity.isLinkSync(getPath(event));
223225
}
224226
return (event[0] & FileSystemEvent._isDir) != 0;
225227
}

tests/standalone_2/io/link_test.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,36 @@ testRelativeLinksSync() {
275275
tempDirectory.deleteSync(recursive: true);
276276
}
277277

278+
testIsDir() async {
279+
if (!Platform.isWindows && !Platform.isLinux && !Platform.isMacOS) return;
280+
Directory sandbox = Directory.systemTemp.createTempSync();
281+
Directory dir = new Directory(sandbox.path + Platform.pathSeparator + "dir");
282+
dir.createSync();
283+
File target = new File(sandbox.path + Platform.pathSeparator + "target");
284+
target.createSync();
285+
286+
final eventCompleter = new Completer<FileSystemEvent>();
287+
var subscription;
288+
subscription = dir.watch().listen((FileSystemEvent event) {
289+
if (event.path.endsWith('link')) {
290+
eventCompleter.complete(event);
291+
subscription.cancel();
292+
}
293+
});
294+
Link link = new Link(dir.path + Platform.pathSeparator + "link");
295+
link.createSync(target.path);
296+
final event = await eventCompleter.future;
297+
// Link should not be marked as Dir.
298+
Expect.isFalse(event.isDirectory);
299+
300+
sandbox.deleteSync(recursive: true);
301+
}
302+
278303
main() {
279304
testCreateSync();
280305
testCreateLoopingLink();
281306
testRenameSync();
282307
testLinkErrorSync();
283308
testRelativeLinksSync();
309+
testIsDir();
284310
}

0 commit comments

Comments
 (0)