diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java index 159e9e67f1a8..48cbab0df088 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java @@ -378,9 +378,22 @@ public class PersistentFSImpl extends PersistentFS implements ApplicationCompone @Override public int getId(@NotNull final VirtualFile parent, @NotNull final String childName, @NotNull final NewVirtualFileSystem fs) { - final int parentId = getFileId(parent); + int parentId = getFileId(parent); - final int[] children = FSRecords.list(parentId); + if (parent == myFakeRoot) { + // children of the fake root must be the FS roots only + myRootsLock.readLock().lock(); + try { + String rootUrl = fs.getProtocol() + "://" + VfsImplUtil.normalize(fs, childName); + VirtualFileSystemEntry root = myRoots.get(rootUrl); + return root == null ? 0 : root.getId(); + } + finally { + myRootsLock.readLock().unlock(); + } + } + + int[] children = FSRecords.list(parentId); if (children.length > 0) { // fast path, check that some child has same nameId as given name, this avoid O(N) on retrieving names for processing non-cached children diff --git a/platform/platform-tests/testSrc/com/intellij/util/io/PersistentFSTest.java b/platform/platform-tests/testSrc/com/intellij/util/io/PersistentFSTest.java index 6692086ca057..f48e2470808e 100644 --- a/platform/platform-tests/testSrc/com/intellij/util/io/PersistentFSTest.java +++ b/platform/platform-tests/testSrc/com/intellij/util/io/PersistentFSTest.java @@ -45,4 +45,19 @@ public class PersistentFSTest extends PlatformTestCase { assertNull(PersistentFS.getInstance().findFileById(id)); } + + public void testListChildrenOfTheRootOfTheRoot() { + PersistentFS fs = PersistentFS.getInstance(); + VirtualFile fakeRoot = fs.findRoot("", LocalFileSystem.getInstance()); + int users = fs.getId(fakeRoot, "Users", LocalFileSystem.getInstance()); + assertEquals(0, users); + int win = fs.getId(fakeRoot, "Windows", LocalFileSystem.getInstance()); + assertEquals(0, win); + + VirtualFile[] roots = fs.getRoots(LocalFileSystem.getInstance()); + for (VirtualFile root : roots) { + int rid = fs.getId(fakeRoot, root.getName(), LocalFileSystem.getInstance()); + assertTrue(0 != rid); + } + } }