Skip to content

Commit 49d743f

Browse files
zichanggcommit-bot@chromium.org
authored andcommitted
[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>
1 parent 56991ad commit 49d743f

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,33 @@ testRelativeLinksSync() {
275275
tempDirectory.deleteSync(recursive: true);
276276
}
277277

278+
testIsDir() async {
279+
Directory sandbox = Directory.systemTemp.createTempSync();
280+
Directory dir = new Directory(sandbox.path + Platform.pathSeparator + "dir");
281+
dir.createSync();
282+
File target = new File(sandbox.path + Platform.pathSeparator + "target");
283+
target.createSync();
284+
285+
final eventCompleter = new Completer<FileSystemEvent>();
286+
var subscription;
287+
subscription = dir.watch().listen((FileSystemEvent event) {
288+
eventCompleter.complete(event);
289+
subscription.cancel();
290+
});
291+
Link link = new Link(dir.path + Platform.pathSeparator + "link");
292+
link.createSync(target.path);
293+
final event = await eventCompleter.future;
294+
// Link should not be marked as Dir.
295+
Expect.isFalse(event.isDirectory);
296+
297+
sandbox.deleteSync(recursive: true);
298+
}
299+
278300
main() {
279301
testCreateSync();
280302
testCreateLoopingLink();
281303
testRenameSync();
282304
testLinkErrorSync();
283305
testRelativeLinksSync();
306+
testIsDir();
284307
}

0 commit comments

Comments
 (0)