From 3dff69979b15b51d2fc04d7a8bf2f29df1b0bd48 Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 13 Sep 2022 12:02:15 +0200 Subject: [PATCH] Utils: "Fix" UNC file path parsing ... by adapting the expectations. Change-Id: If3a3fe2def370440f1edbbcb5a1c2646f1239f67 Reviewed-by: Christian Stenger --- src/libs/utils/filepath.cpp | 35 ++------------------ tests/auto/utils/fileutils/tst_fileutils.cpp | 4 +-- 2 files changed, 4 insertions(+), 35 deletions(-) diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp index f1945d98023..1b478bb6d4a 100644 --- a/src/libs/utils/filepath.cpp +++ b/src/libs/utils/filepath.cpp @@ -8,7 +8,6 @@ #include "fileutils.h" #include "hostosinfo.h" #include "qtcassert.h" -#include "stringutils.h" #include #include @@ -131,6 +130,8 @@ inline bool isWindowsDriveLetter(QChar ch); code from QString based file path to FilePath. An exception here are fragments of paths of a FilePath that are later used with \c pathAppended() or similar which should be kept as QString. + + UNC paths will retain their "//" begin, and are recognizable by this. */ FilePath::FilePath() @@ -770,38 +771,6 @@ bool isWindowsDriveLetter(QChar ch) return (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'); } -using RootAndPath = QPair; - -std::optional windowsRootAndPath(const QStringView path) -{ - const QChar slash('/'); - QStringView workPath = path; - if (workPath.size() < 2) - return {}; - if (workPath.startsWith(slash)) - workPath = workPath.mid(1); - - if (workPath.startsWith(slash)) { - // Its a UNC path ( //server/share/path ) - workPath = workPath.mid(1); - const auto firstSlash = workPath.indexOf(slash); - - // If the first slash is not found, we either received "//" or "//server" - // If we only received "//" we return an empty root name, otherwise - // we return "//server" as root name. - if (firstSlash == -1) - return RootAndPath{path.length() > 2 ? path : workPath, {}}; - - workPath = workPath.mid(firstSlash + 1); - return RootAndPath{chopIfEndsWith(path.mid(0, path.length() - workPath.length()), '/'), - workPath}; - } - - if (workPath.length() > 1 && workPath[1] == ':' && isWindowsDriveLetter(workPath[0])) - return RootAndPath{workPath.mid(0, 2), workPath.mid(3)}; - return {}; -} - void FilePath::setPath(QStringView path) { if (path.startsWith(QStringLiteral("/./"))) diff --git a/tests/auto/utils/fileutils/tst_fileutils.cpp b/tests/auto/utils/fileutils/tst_fileutils.cpp index 1e8f2f405ee..aa50abe698e 100644 --- a/tests/auto/utils/fileutils/tst_fileutils.cpp +++ b/tests/auto/utils/fileutils/tst_fileutils.cpp @@ -399,8 +399,8 @@ void tst_fileutils::fromString_data() QTest::newRow("qrc") << D(":/test.txt", "", "", ":/test.txt"); QTest::newRow("qrc-no-slash") << D(":test.txt", "", "", ":test.txt"); - QTest::newRow("unc-incomplete") << D("//", "", "", "", FailEverywhere); - QTest::newRow("unc-incomplete-only-server") << D("//server", "", "", "//server/", FailEverywhere); + QTest::newRow("unc-incomplete") << D("//", "", "", "//"); + QTest::newRow("unc-incomplete-only-server") << D("//server", "", "", "//server"); QTest::newRow("unc-incomplete-only-server-2") << D("//server/", "", "", "//server/"); QTest::newRow("unc-server-and-share") << D("//server/share", "", "", "//server/share"); QTest::newRow("unc-server-and-share-2") << D("//server/share/", "", "", "//server/share/");