mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
do not duplicate invalid roots
This commit is contained in:
+15
-2
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user