forked from qt-creator/qt-creator
Utils: Port some FilePath part accessors to QStringView
Change-Id: Ib5cc262e44c73880b6538eed714365e3d685870a Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -1213,7 +1213,7 @@ static QList<Utils::FilePath> minimalPrefixPaths(const QList<Utils::FilePath> &p
|
|||||||
// find minimal prefix, ensure '/' at end
|
// find minimal prefix, ensure '/' at end
|
||||||
for (Utils::FilePath path : qAsConst(paths)) {
|
for (Utils::FilePath path : qAsConst(paths)) {
|
||||||
if (!path.endsWith("/"))
|
if (!path.endsWith("/"))
|
||||||
path.setPath(path.path() + "/");
|
path.setPath(QString(path.path() + "/"));
|
||||||
if (path.path().length() > 1)
|
if (path.path().length() > 1)
|
||||||
sortedPaths.append(path);
|
sortedPaths.append(path);
|
||||||
}
|
}
|
||||||
|
@@ -60,7 +60,7 @@ FilePath BuildableHelperLibrary::qtChooserToQmakePath(const FilePath &qtChooser)
|
|||||||
return {};
|
return {};
|
||||||
|
|
||||||
FilePath qmake = qtChooser;
|
FilePath qmake = qtChooser;
|
||||||
qmake.setPath(output.mid(pos, end - pos) + "/qmake");
|
qmake.setPath(QString(output.mid(pos, end - pos) + "/qmake"));
|
||||||
return qmake;
|
return qmake;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -340,17 +340,46 @@ QString FilePath::completeSuffix() const
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void FilePath::setScheme(const QString &scheme)
|
void FilePath::setScheme(const QStringView scheme)
|
||||||
{
|
{
|
||||||
QTC_CHECK(!scheme.contains('/'));
|
QTC_CHECK(!scheme.contains('/'));
|
||||||
m_scheme = scheme;
|
m_scheme = scheme.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FilePath::setHost(const QString &host)
|
void FilePath::setHost(const QStringView host)
|
||||||
{
|
{
|
||||||
m_host = host;
|
m_host = host.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FilePath::setPath(const QStringView path)
|
||||||
|
{
|
||||||
|
setRootAndPath(path, HostOsInfo::hostOs());
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringView FilePath::scheme() const
|
||||||
|
{
|
||||||
|
return m_scheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringView FilePath::host() const
|
||||||
|
{
|
||||||
|
return m_host;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString FilePath::path() const
|
||||||
|
{
|
||||||
|
return m_root + m_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringView FilePath::root() const
|
||||||
|
{
|
||||||
|
return m_root;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FilePath::setRoot(const QStringView root)
|
||||||
|
{
|
||||||
|
m_root = root.toString();
|
||||||
|
}
|
||||||
|
|
||||||
/// \returns a bool indicating whether a file with this
|
/// \returns a bool indicating whether a file with this
|
||||||
/// FilePath exists.
|
/// FilePath exists.
|
||||||
|
@@ -89,17 +89,17 @@ public:
|
|||||||
QVariant toVariant() const;
|
QVariant toVariant() const;
|
||||||
QUrl toUrl() const;
|
QUrl toUrl() const;
|
||||||
|
|
||||||
QString scheme() const { return m_scheme; }
|
QStringView scheme() const;
|
||||||
void setScheme(const QString &scheme);
|
void setScheme(const QStringView scheme);
|
||||||
|
|
||||||
QString host() const { return m_host; }
|
QStringView host() const;
|
||||||
void setHost(const QString &host);
|
void setHost(const QStringView host);
|
||||||
|
|
||||||
QString path() const { return m_root + m_path; }
|
QString path() const;
|
||||||
void setPath(const QString &path) { setRootAndPath(path, HostOsInfo::hostOs()); }
|
void setPath(const QStringView path);
|
||||||
|
|
||||||
QString root() const { return m_root; }
|
QStringView root() const;
|
||||||
void setRoot(const QString &root) { m_root = root; }
|
void setRoot(const QStringView root);
|
||||||
|
|
||||||
QString fileName() const;
|
QString fileName() const;
|
||||||
QString fileNameWithPathComponents(int pathComponents) const;
|
QString fileNameWithPathComponents(int pathComponents) const;
|
||||||
|
@@ -408,7 +408,7 @@ FilePath FileUtils::commonPath(const FilePaths &paths)
|
|||||||
FilePath result;
|
FilePath result;
|
||||||
|
|
||||||
// Common scheme
|
// Common scheme
|
||||||
const QString &commonScheme = first.scheme();
|
const QStringView commonScheme = first.scheme();
|
||||||
auto sameScheme = [&commonScheme] (const FilePath &fp) {
|
auto sameScheme = [&commonScheme] (const FilePath &fp) {
|
||||||
return commonScheme == fp.scheme();
|
return commonScheme == fp.scheme();
|
||||||
};
|
};
|
||||||
@@ -417,7 +417,7 @@ FilePath FileUtils::commonPath(const FilePaths &paths)
|
|||||||
result.setScheme(commonScheme);
|
result.setScheme(commonScheme);
|
||||||
|
|
||||||
// Common host
|
// Common host
|
||||||
const QString &commonHost = first.host();
|
const QStringView commonHost = first.host();
|
||||||
auto sameHost = [&commonHost] (const FilePath &fp) {
|
auto sameHost = [&commonHost] (const FilePath &fp) {
|
||||||
return commonHost == fp.host();
|
return commonHost == fp.host();
|
||||||
};
|
};
|
||||||
|
@@ -78,14 +78,14 @@ QStringList &FSEngine::deviceSchemes()
|
|||||||
return g_deviceSchemes;
|
return g_deviceSchemes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FSEngine::registerDeviceScheme(const QString &scheme)
|
void FSEngine::registerDeviceScheme(const QStringView scheme)
|
||||||
{
|
{
|
||||||
deviceSchemes().append(scheme);
|
deviceSchemes().append(scheme.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void FSEngine::unregisterDeviceScheme(const QString &scheme)
|
void FSEngine::unregisterDeviceScheme(const QStringView scheme)
|
||||||
{
|
{
|
||||||
deviceSchemes().removeAll(scheme);
|
deviceSchemes().removeAll(scheme.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList FSEngine::registeredDeviceSchemes()
|
QStringList FSEngine::registeredDeviceSchemes()
|
||||||
|
@@ -51,8 +51,8 @@ public:
|
|||||||
static void addDevice(const Utils::FilePath &deviceRoot);
|
static void addDevice(const Utils::FilePath &deviceRoot);
|
||||||
static void removeDevice(const Utils::FilePath &deviceRoot);
|
static void removeDevice(const Utils::FilePath &deviceRoot);
|
||||||
|
|
||||||
static void registerDeviceScheme(const QString &scheme);
|
static void registerDeviceScheme(const QStringView scheme);
|
||||||
static void unregisterDeviceScheme(const QString &scheme);
|
static void unregisterDeviceScheme(const QStringView scheme);
|
||||||
static QStringList registeredDeviceSchemes();
|
static QStringList registeredDeviceSchemes();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@@ -295,8 +295,8 @@ FilePath MacroExpander::expand(const FilePath &fileNameWithVariables) const
|
|||||||
{
|
{
|
||||||
FilePath result = fileNameWithVariables;
|
FilePath result = fileNameWithVariables;
|
||||||
result.setPath(expand(result.path()));
|
result.setPath(expand(result.path()));
|
||||||
result.setHost(expand(result.host()));
|
result.setHost(expand(result.host().toString()));
|
||||||
result.setScheme(expand(result.scheme()));
|
result.setScheme(expand(result.scheme().toString()));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -28,7 +28,7 @@
|
|||||||
namespace Docker::Constants {
|
namespace Docker::Constants {
|
||||||
|
|
||||||
const char DOCKER[] = "docker";
|
const char DOCKER[] = "docker";
|
||||||
const char DOCKER_DEVICE_SCHEME[] = "docker";
|
const char16_t DOCKER_DEVICE_SCHEME[] = u"docker";
|
||||||
|
|
||||||
const char DOCKER_SETTINGS_ID[] = "Docker.Settings";
|
const char DOCKER_SETTINGS_ID[] = "Docker.Settings";
|
||||||
const char DOCKER_DEVICE_TYPE[] = "DockerDeviceType";
|
const char DOCKER_DEVICE_TYPE[] = "DockerDeviceType";
|
||||||
|
@@ -614,7 +614,7 @@ FilePath DockerDevice::mapToGlobalPath(const FilePath &pathOnDevice) const
|
|||||||
|
|
||||||
FilePath result;
|
FilePath result;
|
||||||
result.setPath(pathOnDevice.path());
|
result.setPath(pathOnDevice.path());
|
||||||
result.setScheme("docker");
|
result.setScheme(Constants::DOCKER_DEVICE_SCHEME);
|
||||||
result.setHost(d->m_data.repoAndTag());
|
result.setHost(d->m_data.repoAndTag());
|
||||||
|
|
||||||
// The following would work, but gives no hint on repo and tag
|
// The following would work, but gives no hint on repo and tag
|
||||||
@@ -646,18 +646,23 @@ Utils::FilePath DockerDevice::rootPath() const
|
|||||||
FilePath root;
|
FilePath root;
|
||||||
root.setScheme(Constants::DOCKER_DEVICE_SCHEME);
|
root.setScheme(Constants::DOCKER_DEVICE_SCHEME);
|
||||||
root.setHost(d->m_data.repoAndTag());
|
root.setHost(d->m_data.repoAndTag());
|
||||||
root.setPath("/");
|
root.setPath(u"/");
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DockerDevice::handlesFile(const FilePath &filePath) const
|
bool DockerDevice::handlesFile(const FilePath &filePath) const
|
||||||
{
|
{
|
||||||
if (filePath.scheme() == "device" && filePath.host() == id().toString())
|
if (filePath.scheme() == u"device" && filePath.host() == id().toString())
|
||||||
return true;
|
return true;
|
||||||
if (filePath.scheme() == "docker" && filePath.host() == d->m_data.imageId)
|
|
||||||
|
if (filePath.scheme() == Constants::DOCKER_DEVICE_SCHEME
|
||||||
|
&& filePath.host() == d->m_data.imageId)
|
||||||
return true;
|
return true;
|
||||||
if (filePath.scheme() == "docker" && filePath.host() == d->m_data.repo + ':' + d->m_data.tag)
|
|
||||||
|
if (filePath.scheme() == Constants::DOCKER_DEVICE_SCHEME
|
||||||
|
&& filePath.host() == QString(d->m_data.repo + ':' + d->m_data.tag))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -377,7 +377,7 @@ IDevice::ConstPtr DeviceManager::deviceForPath(const FilePath &path)
|
|||||||
{
|
{
|
||||||
const QList<IDevice::Ptr> devices = instance()->d->deviceList();
|
const QList<IDevice::Ptr> devices = instance()->d->deviceList();
|
||||||
|
|
||||||
if (path.scheme() == "device") {
|
if (path.scheme() == u"device") {
|
||||||
for (const IDevice::Ptr &dev : devices) {
|
for (const IDevice::Ptr &dev : devices) {
|
||||||
if (path.host() == dev->id().toString())
|
if (path.host() == dev->id().toString())
|
||||||
return dev;
|
return dev;
|
||||||
|
@@ -220,7 +220,7 @@ FilePath IDevice::mapToGlobalPath(const FilePath &pathOnDevice) const
|
|||||||
// match DeviceManager::deviceForPath
|
// match DeviceManager::deviceForPath
|
||||||
FilePath result;
|
FilePath result;
|
||||||
result.setPath(pathOnDevice.path());
|
result.setPath(pathOnDevice.path());
|
||||||
result.setScheme("device");
|
result.setScheme(u"device");
|
||||||
result.setHost(id().toString());
|
result.setHost(id().toString());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -237,7 +237,7 @@ FilePath IDevice::filePath(const QString &pathOnDevice) const
|
|||||||
|
|
||||||
bool IDevice::handlesFile(const FilePath &filePath) const
|
bool IDevice::handlesFile(const FilePath &filePath) const
|
||||||
{
|
{
|
||||||
if (filePath.scheme() == "device" && filePath.host() == id().toString())
|
if (filePath.scheme() == u"device" && filePath.host() == id().toString())
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -781,9 +781,9 @@ void IDevice::setMachineType(MachineType machineType)
|
|||||||
FilePath IDevice::rootPath() const
|
FilePath IDevice::rootPath() const
|
||||||
{
|
{
|
||||||
FilePath root;
|
FilePath root;
|
||||||
root.setScheme("device");
|
root.setScheme(u"device");
|
||||||
root.setHost(id().toString());
|
root.setHost(id().toString());
|
||||||
root.setPath("/");
|
root.setPath(u"/");
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1048,20 +1048,20 @@ QString LinuxDevice::userAtHost() const
|
|||||||
return sshParameters().userAtHost();
|
return sshParameters().userAtHost();
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::FilePath LinuxDevice::rootPath() const
|
FilePath LinuxDevice::rootPath() const
|
||||||
{
|
{
|
||||||
Utils::FilePath root;
|
FilePath root;
|
||||||
root.setScheme("ssh");
|
root.setScheme(u"ssh");
|
||||||
root.setHost(userAtHost());
|
root.setHost(userAtHost());
|
||||||
root.setPath("/");
|
root.setPath(u"/");
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LinuxDevice::handlesFile(const FilePath &filePath) const
|
bool LinuxDevice::handlesFile(const FilePath &filePath) const
|
||||||
{
|
{
|
||||||
if (filePath.scheme() == "device" && filePath.host() == id().toString())
|
if (filePath.scheme() == u"device" && filePath.host() == id().toString())
|
||||||
return true;
|
return true;
|
||||||
if (filePath.scheme() == "ssh" && filePath.host() == userAtHost())
|
if (filePath.scheme() == u"ssh" && filePath.host() == userAtHost())
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -117,12 +117,12 @@ static RemoteLinuxPluginPrivate *dd = nullptr;
|
|||||||
RemoteLinuxPlugin::RemoteLinuxPlugin()
|
RemoteLinuxPlugin::RemoteLinuxPlugin()
|
||||||
{
|
{
|
||||||
setObjectName(QLatin1String("RemoteLinuxPlugin"));
|
setObjectName(QLatin1String("RemoteLinuxPlugin"));
|
||||||
FSEngine::registerDeviceScheme("ssh");
|
FSEngine::registerDeviceScheme(u"ssh");
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoteLinuxPlugin::~RemoteLinuxPlugin()
|
RemoteLinuxPlugin::~RemoteLinuxPlugin()
|
||||||
{
|
{
|
||||||
FSEngine::unregisterDeviceScheme("ssh");
|
FSEngine::unregisterDeviceScheme(u"ssh");
|
||||||
delete dd;
|
delete dd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -188,9 +188,9 @@ void tst_fsengine::initTestCase()
|
|||||||
void tst_fsengine::testFilePathFromToString()
|
void tst_fsengine::testFilePathFromToString()
|
||||||
{
|
{
|
||||||
FilePath p = FilePath::fromString("device://test/test.txt");
|
FilePath p = FilePath::fromString("device://test/test.txt");
|
||||||
QCOMPARE(p.scheme(), "device");
|
QCOMPARE(p.scheme(), u"device");
|
||||||
QCOMPARE(p.host(), "test");
|
QCOMPARE(p.host(), u"test");
|
||||||
QCOMPARE(p.path(), "/test.txt");
|
QCOMPARE(p.path(), u"/test.txt");
|
||||||
|
|
||||||
QString asString = p.toString();
|
QString asString = p.toString();
|
||||||
QCOMPARE(asString,
|
QCOMPARE(asString,
|
||||||
@@ -198,9 +198,9 @@ void tst_fsengine::testFilePathFromToString()
|
|||||||
+ "/test/test.txt");
|
+ "/test/test.txt");
|
||||||
|
|
||||||
FilePath p2 = FilePath::fromString(asString);
|
FilePath p2 = FilePath::fromString(asString);
|
||||||
QCOMPARE(p.scheme(), "device");
|
QCOMPARE(p.scheme(), u"device");
|
||||||
QCOMPARE(p.host(), "test");
|
QCOMPARE(p.host(), u"test");
|
||||||
QCOMPARE(p.path(), "/test.txt");
|
QCOMPARE(p.path(), u"/test.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_fsengine::testRootPathContainsFakeDir()
|
void tst_fsengine::testRootPathContainsFakeDir()
|
||||||
|
Reference in New Issue
Block a user