From 00fd4c8feadbfe354b8c7f93038f60bec86b5554 Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Wed, 22 Feb 2023 15:58:18 +0100 Subject: [PATCH] Utils: Fix diriterator for scheme folders Previously the "fileName" of every device inside a scheme subfolder would be empty. Therefore QDirIterator would skip them. Change-Id: Ifa46859aadbd8a81364a1fe0a72b9a50a7a396ca Reviewed-by: Eike Ziller Reviewed-by: Qt CI Bot --- src/libs/utils/filepath.cpp | 6 ++++ src/libs/utils/fsengine/diriterator.h | 3 ++ tests/auto/utils/fileutils/tst_fileutils.cpp | 34 ++++++++++++++++---- tests/auto/utils/fsengine/tst_fsengine.cpp | 4 +++ 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp index 0e46b61c7d8..8c0832df585 100644 --- a/src/libs/utils/filepath.cpp +++ b/src/libs/utils/filepath.cpp @@ -233,6 +233,9 @@ QString FilePath::toString() const if (!needsDevice()) return path(); + if (pathView().isEmpty()) + return scheme() + "://" + encodedHost(); + if (isRelativePath()) return scheme() + "://" + encodedHost() + "/./" + pathView(); return scheme() + "://" + encodedHost() + pathView(); @@ -255,6 +258,9 @@ QString FilePath::toFSPathString() const if (scheme().isEmpty()) return path(); + if (pathView().isEmpty()) + return specialRootPath() + '/' + scheme() + '/' + encodedHost(); + if (isRelativePath()) return specialRootPath() + '/' + scheme() + '/' + encodedHost() + "/./" + pathView(); return specialRootPath() + '/' + scheme() + '/' + encodedHost() + pathView(); diff --git a/src/libs/utils/fsengine/diriterator.h b/src/libs/utils/fsengine/diriterator.h index 9daebbebaaa..54e9d5d2dd3 100644 --- a/src/libs/utils/fsengine/diriterator.h +++ b/src/libs/utils/fsengine/diriterator.h @@ -39,6 +39,9 @@ public: QString currentFileName() const override { const QString result = it->fileName(); + if (result.isEmpty() && !it->host().isEmpty()) { + return it->host().toString(); + } return chopIfEndsWith(result, '/'); } diff --git a/tests/auto/utils/fileutils/tst_fileutils.cpp b/tests/auto/utils/fileutils/tst_fileutils.cpp index 334a7c99e36..46461072e97 100644 --- a/tests/auto/utils/fileutils/tst_fileutils.cpp +++ b/tests/auto/utils/fileutils/tst_fileutils.cpp @@ -473,8 +473,16 @@ void tst_fileutils::toString_data() QTest::addColumn("userResult"); QTest::newRow("empty") << "" << "" << "" << "" << ""; - QTest::newRow("scheme") << "http" << "" << "" << "http:///./" << "http:///./"; - QTest::newRow("scheme-and-host") << "http" << "127.0.0.1" << "" << "http://127.0.0.1/./" << "http://127.0.0.1/./"; + QTest::newRow("scheme") << "http" + << "" + << "" + << "http://" + << "http://"; + QTest::newRow("scheme-and-host") << "http" + << "127.0.0.1" + << "" + << "http://127.0.0.1" + << "http://127.0.0.1"; QTest::newRow("root") << "http" << "127.0.0.1" << "/" << "http://127.0.0.1/" << "http://127.0.0.1/"; QTest::newRow("root-folder") << "" << "" << "/" << "/" << "/"; @@ -483,7 +491,11 @@ void tst_fileutils::toString_data() QTest::newRow("qtc-dev-type-root-folder-linux") << "" << "" << "/__qtc_devices__/docker" << "/__qtc_devices__/docker" << "/__qtc_devices__/docker"; QTest::newRow("qtc-dev-type-root-folder-win") << "" << "" << "c:/__qtc_devices__/docker" << "c:/__qtc_devices__/docker" << "c:/__qtc_devices__/docker"; QTest::newRow("qtc-root-folder") << "docker" << "alpine:latest" << "/" << "docker://alpine:latest/" << "docker://alpine:latest/"; - QTest::newRow("qtc-root-folder-rel") << "docker" << "alpine:latest" << "" << "docker://alpine:latest/./" << "docker://alpine:latest/./"; + QTest::newRow("qtc-root-folder-rel") << "docker" + << "alpine:latest" + << "" + << "docker://alpine:latest" + << "docker://alpine:latest"; } void tst_fileutils::toString() @@ -509,15 +521,25 @@ void tst_fileutils::toFSPathString_data() QTest::addColumn("userResult"); QTest::newRow("empty") << "" << "" << "" << "" << ""; - QTest::newRow("scheme") << "http" << "" << "" << QDir::rootPath() + "__qtc_devices__/http//./" << "http:///./"; - QTest::newRow("scheme-and-host") << "http" << "127.0.0.1" << "" << QDir::rootPath() + "__qtc_devices__/http/127.0.0.1/./" << "http://127.0.0.1/./"; + QTest::newRow("scheme") << "http" + << "" + << "" << QDir::rootPath() + "__qtc_devices__/http/" + << "http://"; + QTest::newRow("scheme-and-host") << "http" + << "127.0.0.1" + << "" << QDir::rootPath() + "__qtc_devices__/http/127.0.0.1" + << "http://127.0.0.1"; QTest::newRow("root") << "http" << "127.0.0.1" << "/" << QDir::rootPath() + "__qtc_devices__/http/127.0.0.1/" << "http://127.0.0.1/"; QTest::newRow("root-folder") << "" << "" << "/" << "/" << "/"; QTest::newRow("qtc-dev-root-folder") << "" << "" << QDir::rootPath() + "__qtc_devices__" << QDir::rootPath() + "__qtc_devices__" << QDir::rootPath() + "__qtc_devices__"; QTest::newRow("qtc-dev-type-root-folder") << "" << "" << QDir::rootPath() + "__qtc_devices__/docker" << QDir::rootPath() + "__qtc_devices__/docker" << QDir::rootPath() + "__qtc_devices__/docker"; QTest::newRow("qtc-root-folder") << "docker" << "alpine:latest" << "/" << QDir::rootPath() + "__qtc_devices__/docker/alpine:latest/" << "docker://alpine:latest/"; - QTest::newRow("qtc-root-folder-rel") << "docker" << "alpine:latest" << "" << QDir::rootPath() + "__qtc_devices__/docker/alpine:latest/./" << "docker://alpine:latest/./"; + QTest::newRow("qtc-root-folder-rel") + << "docker" + << "alpine:latest" + << "" << QDir::rootPath() + "__qtc_devices__/docker/alpine:latest" + << "docker://alpine:latest"; } void tst_fileutils::toFSPathString() diff --git a/tests/auto/utils/fsengine/tst_fsengine.cpp b/tests/auto/utils/fsengine/tst_fsengine.cpp index 8b0cdfc1b45..d350a981808 100644 --- a/tests/auto/utils/fsengine/tst_fsengine.cpp +++ b/tests/auto/utils/fsengine/tst_fsengine.cpp @@ -93,6 +93,10 @@ void tst_fsengine::testRootPathContainsFakeDir() const QStringList schemeList = schemes.entryList(); QVERIFY(schemeList.contains("device")); + QDir devices(FilePath::specialDeviceRootPath()); + const QStringList deviceList = devices.entryList(); + QVERIFY(deviceList.contains("test")); + QDir deviceRoot(FilePath::specialDeviceRootPath() + "/test" + startWithSlash(QDir::rootPath())); const QStringList deviceRootList = deviceRoot.entryList(); QVERIFY(!deviceRootList.isEmpty());