diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp index 6b6c2bbf956..b0b1e7a669d 100644 --- a/src/plugins/cpptools/cppmodelmanager.cpp +++ b/src/plugins/cpptools/cppmodelmanager.cpp @@ -1099,6 +1099,9 @@ void CppModelManager::updateIncludesInPaths(QFutureInterface &future, QStringList suffixes) { QMap entriesInPaths; + typedef QPair SymLink; + typedef QList SymLinks; + SymLinks symlinks; int processed = 0; future.setProgressRange(0, paths.size()); @@ -1111,6 +1114,11 @@ void CppModelManager::updateIncludesInPaths(QFutureInterface &future, break; const QString path = paths.takeFirst(); + + // Skip already scanned paths + if (entriesInPaths.contains(path)) + continue; + QStringList entries; QDirIterator i(path, QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot); @@ -1125,11 +1133,18 @@ void CppModelManager::updateIncludesInPaths(QFutureInterface &future, // Also scan subdirectory, but avoid endless recursion with symbolic links if (fileInfo.isSymLink()) { - QMap::const_iterator result = entriesInPaths.find(fileInfo.canonicalFilePath()); + QString target = fileInfo.symLinkTarget(); + + // Don't add broken symlinks + if (!QFileInfo(target).exists()) + continue; + + QMap::const_iterator result = entriesInPaths.find(target); if (result != entriesInPaths.constEnd()) { entriesInPaths.insert(fileName, result.value()); } else { - paths.append(fileName); + paths.append(target); + symlinks.append(SymLink(fileName, target)); } } else { paths.append(fileName); @@ -1145,6 +1160,14 @@ void CppModelManager::updateIncludesInPaths(QFutureInterface &future, future.setProgressRange(0, processed + paths.size()); future.setProgressValue(processed); } + // link symlinks + QListIterator it(symlinks); + it.toBack(); + while (it.hasPrevious()) { + SymLink v = it.previous(); + QMap::const_iterator result = entriesInPaths.find(v.second); + entriesInPaths.insert(v.first, result.value()); + } manager->setIncludesInPaths(entriesInPaths);