Filepath: Fix operator<()

Previously a QMap with FilePath as key would return wrong
entries when comparing paths with and without scheme/host.

Change-Id: Icc5d119a18c1b7a2fdab9c89f162c48859926523
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Marcus Tillmanns
2024-02-08 15:15:56 +01:00
parent f18dcf2202
commit a020c13e10
2 changed files with 65 additions and 6 deletions

View File

@@ -2334,12 +2334,30 @@ QTCREATOR_UTILS_EXPORT bool operator!=(const FilePath &first, const FilePath &se
QTCREATOR_UTILS_EXPORT bool operator<(const FilePath &first, const FilePath &second)
{
const int cmp = first.pathView().compare(second.pathView(), first.caseSensitivity());
if (cmp != 0)
return cmp < 0;
if (first.host() != second.host())
return first.host() < second.host();
return first.scheme() < second.scheme();
const bool firstNeedsDevice = first.needsDevice();
const bool secondNeedsDevice = second.needsDevice();
// If either needs a device, we have to compare host and scheme first.
if (firstNeedsDevice || secondNeedsDevice) {
// Paths needing a device are "larger" than those not needing one.
if (firstNeedsDevice < secondNeedsDevice)
return true;
else if (firstNeedsDevice > secondNeedsDevice)
return false;
// First we sort by scheme ...
const int s = first.scheme().compare(second.scheme());
if (s != 0)
return s < 0;
// than by host ...
const int h = first.host().compare(second.host());
if (h != 0)
return h < 0;
}
const int p = first.pathView().compare(second.pathView(), first.caseSensitivity());
return p < 0;
}
QTCREATOR_UTILS_EXPORT bool operator<=(const FilePath &first, const FilePath &second)