forked from qt-creator/qt-creator
CompilationDatabase: Fix directory hierarchy
When checking whether a child directory already exists, only check whether that directory is present as a direct child of the given parent, don't search recursively. Otherwise the directory hierarchy in the project outline can get messed up if multiple directories with the same name exist at different levels in the folder hierarchy. Side note: Besides avoiding an incorrect folder hierarchy, avoiding the recursive search also speeds up building up the folder structure (e.g. it took ~4 instead of ~20 seconds for building up the hierarchy of the LibreOffice source tree in my case). Fixes: QTCREATORBUG-21725 Change-Id: I5fc3c5c85d44ad8e3664f29e9143fc070d488c7a Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -258,16 +258,11 @@ FolderNode *addChildFolderNode(FolderNode *parent, const QString &childName)
|
||||
|
||||
FolderNode *addOrGetChildFolderNode(FolderNode *parent, const QString &childName)
|
||||
{
|
||||
Node *childNode = parent->findNode([childName](const Node *node) {
|
||||
if (!node->asFolderNode())
|
||||
return false;
|
||||
QString nodeDirName = node->filePath().fileName();
|
||||
if (nodeDirName.isEmpty())
|
||||
nodeDirName = node->filePath().toString();
|
||||
return nodeDirName == childName;
|
||||
});
|
||||
if (childNode)
|
||||
return childNode->asFolderNode();
|
||||
for (FolderNode *folder : parent->folderNodes()) {
|
||||
if (folder->filePath().fileName() == childName) {
|
||||
return folder;
|
||||
}
|
||||
}
|
||||
|
||||
return addChildFolderNode(parent, childName);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user