Utils: Sanitize FilePath::onDevice()

It's one entry in the FilePath world, so it should start with a QString.

Change-Id: Ib2693f52d56103a4c37ba7361b191c2a5c2a72f8
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
hjk
2022-11-16 15:07:25 +01:00
parent 213d60ad64
commit f59ca97a84
5 changed files with 16 additions and 20 deletions

View File

@@ -29,9 +29,12 @@ namespace Utils {
DeviceFileAccess::~DeviceFileAccess() = default;
QString DeviceFileAccess::mapToDevicePath(const FilePath &filePath) const
// This takes a \a hostPath, typically the same as used with QFileInfo
// and returns the path component of a universal FilePath. Host and scheme
// of the latter are added by a higher level to form a FilePath.
QString DeviceFileAccess::mapToDevicePath(const QString &hostPath) const
{
return filePath.path();
return hostPath;
}
bool DeviceFileAccess::isExecutableFile(const FilePath &filePath) const

View File

@@ -18,7 +18,7 @@ public:
protected:
friend class FilePath;
virtual QString mapToDevicePath(const FilePath &filePath) const;
virtual QString mapToDevicePath(const QString &hostPath) const;
virtual bool isExecutableFile(const FilePath &filePath) const;
virtual bool isReadableFile(const FilePath &filePath) const;

View File

@@ -551,11 +551,6 @@ FilePath FilePath::symLinkTarget() const
return fileAccess()->symLinkTarget(*this);
}
QString FilePath::mapToDevicePath() const
{
return fileAccess()->mapToDevicePath(*this);
}
FilePath FilePath::withExecutableSuffix() const
{
return withNewPath(OsSpecificAspects::withExecutableSuffix(osType(), path()));
@@ -1088,10 +1083,9 @@ FilePath FilePath::onDevice(const FilePath &deviceTemplate) const
return *this;
// TODO: converting paths between different non local devices is still unsupported
QTC_CHECK(!needsDevice());
FilePath res;
res.setParts(deviceTemplate.scheme(), deviceTemplate.host(), path());
res.setPath(res.mapToDevicePath());
return res;
return fromParts(deviceTemplate.scheme(),
deviceTemplate.host(),
deviceTemplate.fileAccess()->mapToDevicePath(path()));
}
/*!

View File

@@ -238,7 +238,6 @@ private:
void setFromString(const QString &filepath);
DeviceFileAccess *fileAccess() const;
[[nodiscard]] QString mapToDevicePath() const;
[[nodiscard]] QString encodedHost() const;
QString m_data; // Concatenated m_path, m_scheme, m_host

View File

@@ -122,7 +122,7 @@ public:
RunResult runInShell(const CommandLine &cmdLine,
const QByteArray &stdInData) const override;
QString mapToDevicePath(const FilePath &filePath) const override;
QString mapToDevicePath(const QString &hostPath) const override;
OsType osType(const FilePath &filePath) const override;
DockerDevicePrivate *m_dev = nullptr;
@@ -354,17 +354,17 @@ RunResult DockerDeviceFileAccess::runInShell(const CommandLine &cmdLine,
return m_dev->runInShell(cmdLine, stdInData);
}
QString DockerDeviceFileAccess::mapToDevicePath(const FilePath &filePath) const
QString DockerDeviceFileAccess::mapToDevicePath(const QString &hostPath) const
{
// make sure to convert windows style paths to unix style paths with the file system case:
// C:/dev/src -> /c/dev/src
const FilePath normalized = FilePath::fromString(filePath.path()).normalizedPathName();
QString path = normalized.path();
const FilePath normalized = FilePath::fromString(hostPath).normalizedPathName();
QString newPath = normalized.path();
if (HostOsInfo::isWindowsHost() && normalized.startsWithDriveLetter()) {
const QChar lowerDriveLetter = path.at(0);
path = '/' + lowerDriveLetter + path.mid(2); // strip C:
const QChar lowerDriveLetter = newPath.at(0);
newPath = '/' + lowerDriveLetter + newPath.mid(2); // strip C:
}
return path;
return newPath;
}
OsType DockerDeviceFileAccess::osType(const FilePath &filePath) const