From cabd5fea919c39b3ef1e2ef1e80ca1418c22c13f Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 14 Oct 2024 15:10:52 +0200 Subject: [PATCH] Cleanup (formatting; typos) GitOrigin-RevId: a4c670b18cd362e44326f8cd616c2b14f42259f7 --- .../vfs/impl/local/LocalFileSystemBase.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemBase.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemBase.java index 21f10efda004..fe586417c8aa 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemBase.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemBase.java @@ -518,17 +518,12 @@ public abstract class LocalFileSystemBase extends LocalFileSystem { if (SystemInfo.isWindows) { return nioFile.toRealPath(LinkOption.NOFOLLOW_LINKS).getFileName().toString(); } - else { - // Handle one common case as quickly as possible: compute the file's realpath, resolving links - // (to avoid quadratic behaviour from directory listing). In general this is not a suitable canonical name for the - // file, because links have been resolved, but if the result compares with case-insensitive equality with the given - // file's path, then the return value is suitable for use as a canonical name. - var resolvedRealPath = nioFile.toRealPath(); - if (resolvedRealPath.toString().equalsIgnoreCase(file.getPath())) { - return resolvedRealPath.getFileName().toString(); - } + // `toRealPath(NOFOLLOW_LINKS)` is too slow on Unix; `toRealPath()` works when there are no symlinks + var realPath = nioFile.toRealPath(); + if (realPath.toString().equalsIgnoreCase(file.getPath())) { + return realPath.getFileName().toString(); } - // `Path#toRealPath` resolves the whole path starting from the root, but only the last component is necessary + // last resort: listing files in the parent directory try (var stream = Files.newDirectoryStream(convertToNioFileAndCheck(parent, false))) { for (var path : stream) { var name = path.getFileName().toString();