forked from qt-creator/qt-creator
Utils: Fix bug in commonPath() with directories
The algorithm expected a list of filenames, but the cmake plugin passed in a list containing a directory and a filename. Appending a slash to each entry. (Except root entries.) fixes this. Task-number: QTCREATORBUG-13606 Change-Id: I518a2601295017636f4c450cc8a9026f4b41689a Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
@@ -32,6 +32,8 @@
|
||||
|
||||
#include "hostosinfo.h"
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
#include <QDir>
|
||||
|
||||
#include <limits.h>
|
||||
@@ -87,7 +89,12 @@ QTCREATOR_UTILS_EXPORT QString commonPrefix(const QStringList &strings)
|
||||
|
||||
QTCREATOR_UTILS_EXPORT QString commonPath(const QStringList &files)
|
||||
{
|
||||
QString common = commonPrefix(files);
|
||||
QStringList appendedSlashes = Utils::transform(files, [](const QString &file) -> QString {
|
||||
if (!file.endsWith(QLatin1Char('/')))
|
||||
return QString(file + QLatin1Char('/'));
|
||||
return file;
|
||||
});
|
||||
QString common = commonPrefix(appendedSlashes);
|
||||
// Find common directory part: "C:\foo\bar" -> "C:\foo"
|
||||
int lastSeparatorPos = common.lastIndexOf(QLatin1Char('/'));
|
||||
if (lastSeparatorPos == -1)
|
||||
|
||||
Reference in New Issue
Block a user