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();