From 20e3d536021bce6b1e80ba64f19a7045d67b6b1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= <thorbjorn.lindeijer@nokia.com> Date: Fri, 28 Aug 2009 16:54:38 +0200 Subject: [PATCH] Fixed endless looping in include paths in some cases with symlinks Done-with: Christian Kamm <christian.d.kamm@nokia.com> --- src/plugins/cpptools/cppmodelmanager.cpp | 27 ++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) 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<void> &future, QStringList suffixes) { QMap<QString, QStringList> entriesInPaths; + typedef QPair<QString, QString> SymLink; + typedef QList<SymLink> SymLinks; + SymLinks symlinks; int processed = 0; future.setProgressRange(0, paths.size()); @@ -1111,6 +1114,11 @@ void CppModelManager::updateIncludesInPaths(QFutureInterface<void> &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<void> &future, // Also scan subdirectory, but avoid endless recursion with symbolic links if (fileInfo.isSymLink()) { - QMap<QString, QStringList>::const_iterator result = entriesInPaths.find(fileInfo.canonicalFilePath()); + QString target = fileInfo.symLinkTarget(); + + // Don't add broken symlinks + if (!QFileInfo(target).exists()) + continue; + + QMap<QString, QStringList>::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<void> &future, future.setProgressRange(0, processed + paths.size()); future.setProgressValue(processed); } + // link symlinks + QListIterator<SymLink> it(symlinks); + it.toBack(); + while (it.hasPrevious()) { + SymLink v = it.previous(); + QMap<QString, QStringList>::const_iterator result = entriesInPaths.find(v.second); + entriesInPaths.insert(v.first, result.value()); + } manager->setIncludesInPaths(entriesInPaths); -- GitLab