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 <eike.ziller@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Marcus Tillmanns
2023-02-22 15:58:18 +01:00
parent d44126c300
commit 00fd4c8fea
4 changed files with 41 additions and 6 deletions

View File

@@ -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();

View File

@@ -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, '/');
}

View File

@@ -473,8 +473,16 @@ void tst_fileutils::toString_data()
QTest::addColumn<QString>("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<QString>("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()

View File

@@ -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());