Commit 17838d81 authored by Kai Koehne's avatar Kai Koehne Committed by Christiaan Janssen
Browse files

FileInProjectFinder: Try to find path in list of files even if project directory is empty

Change-Id: I4c7e783b7fc43fc3ff68a04fcb2ff3b2cf14e109
Reviewed-on: http://codereview.qt.nokia.com/310

Reviewed-by: default avatarQt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: default avatarChristiaan Janssen <christiaan.janssen@nokia.com>
parent be1dee19
...@@ -97,37 +97,36 @@ void FileInProjectFinder::setProjectFiles(const QStringList &projectFiles) ...@@ -97,37 +97,36 @@ void FileInProjectFinder::setProjectFiles(const QStringList &projectFiles)
*/ */
QString FileInProjectFinder::findFile(const QString &originalPath, bool *success) const QString FileInProjectFinder::findFile(const QString &originalPath, bool *success) const
{ {
if (m_projectDir.isEmpty()) if (!m_projectDir.isEmpty()) {
return originalPath; const QChar separator = QLatin1Char('/');
if (originalPath.startsWith(m_projectDir + separator)) {
const QChar separator = QLatin1Char('/'); if (success)
if (originalPath.startsWith(m_projectDir + separator)) { *success = true;
if (success) return originalPath;
*success = true; }
return originalPath;
}
if (m_cache.contains(originalPath)) { if (m_cache.contains(originalPath)) {
if (success) if (success)
*success = true; *success = true;
return m_cache.value(originalPath); return m_cache.value(originalPath);
} }
// Strip directories one by one from the beginning of the path, // Strip directories one by one from the beginning of the path,
// and see if the new relative path exists in the build directory. // and see if the new relative path exists in the build directory.
if (originalPath.contains(separator)) { if (originalPath.contains(separator)) {
for (int pos = originalPath.indexOf(separator); pos != -1; for (int pos = originalPath.indexOf(separator); pos != -1;
pos = originalPath.indexOf(separator, pos + 1)) { pos = originalPath.indexOf(separator, pos + 1)) {
QString candidate = originalPath; QString candidate = originalPath;
candidate.remove(0, pos); candidate.remove(0, pos);
candidate.prepend(m_projectDir); candidate.prepend(m_projectDir);
QFileInfo candidateInfo(candidate); QFileInfo candidateInfo(candidate);
if (candidateInfo.exists() && candidateInfo.isFile()) { if (candidateInfo.exists() && candidateInfo.isFile()) {
if (success) if (success)
*success = true; *success = true;
m_cache.insert(originalPath, candidate); m_cache.insert(originalPath, candidate);
return candidate; return candidate;
}
} }
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment