do not duplicate invalid roots

This commit is contained in:
Alexey Kudravtsev
2013-03-14 17:23:34 +04:00
parent b82d68944b
commit e45bda80cc
2 changed files with 30 additions and 2 deletions
@@ -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
@@ -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);
}
}
}