Utils: Make FilePath::toFSPathString a full copy of toString

Changing the toString() to prepend system-specific prefixes
to cater for the remote filesystem model handling had unintended
sideeffects.

This here is the first step to split both paths.

Change-Id: I66cdd9a87802408e2ba95c2e29b9d7cce7fe2553
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2022-09-16 10:00:09 +02:00
parent f99e17efa4
commit 31556332f5
2 changed files with 43 additions and 2 deletions

View File

@@ -186,6 +186,7 @@ QString FilePath::toString() const
if (m_scheme.isEmpty())
return m_path;
// FIXME: This OS-independent URL-style output
if (isRelativePath())
return specialPath(SpecialPathComponent::RootPath) + "/" + m_scheme + "/" + encodedHost() + "/./" + m_path;
return specialPath(SpecialPathComponent::RootPath) + "/" + m_scheme + "/" + encodedHost() + m_path;
@@ -193,8 +194,12 @@ QString FilePath::toString() const
QString FilePath::toFSPathString() const
{
// TODO ...
return toString();
if (m_scheme.isEmpty())
return m_path;
if (isRelativePath())
return specialPath(SpecialPathComponent::RootPath) + "/" + m_scheme + "/" + encodedHost() + "/./" + m_path;
return specialPath(SpecialPathComponent::RootPath) + "/" + m_scheme + "/" + encodedHost() + m_path;
}
QUrl FilePath::toUrl() const

View File

@@ -46,6 +46,8 @@ private slots:
void fromString();
void toString_data();
void toString();
void toFSPathString_data();
void toFSPathString();
void comparison_data();
void comparison();
void linkFromString_data();
@@ -320,6 +322,40 @@ void tst_fileutils::toString()
QCOMPARE(cleanedOutput, userResult);
}
void tst_fileutils::toFSPathString_data()
{
QTest::addColumn<QString>("scheme");
QTest::addColumn<QString>("host");
QTest::addColumn<QString>("path");
QTest::addColumn<QString>("result");
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("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/./";
}
void tst_fileutils::toFSPathString()
{
QFETCH(QString, scheme);
QFETCH(QString, host);
QFETCH(QString, path);
QFETCH(QString, result);
QFETCH(QString, userResult);
FilePath filePath = FilePath::fromParts(scheme, host, path);
QCOMPARE(filePath.toFSPathString(), result);
QString cleanedOutput = filePath.needsDevice() ? filePath.toUserOutput() : QDir::cleanPath(filePath.toUserOutput());
QCOMPARE(cleanedOutput, userResult);
}
enum ExpectedPass
{
PassEverywhere = 0,