aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhjk <hjk@qt.io>2021-10-08 10:31:30 +0200
committerhjk <hjk@qt.io>2021-10-12 11:24:29 +0000
commit34b42a477229bd2e57137909fcf9724f56c20068 (patch)
treed20ed03618437de91054f0eaffff5f810febb41b
parentf49fbe7f582737efbd65c737da782af8473b9224 (diff)
Utils: Introduce FilePath::mapTo{Device,Global}Path
Re-directing via IDevice::mapTo{Device,Global}Path Change-Id: Ica957839479967790bbd93e90eced66aa0b122a8 Reviewed-by: David Schulz <david.schulz@qt.io>
-rw-r--r--src/libs/utils/filepath.cpp18
-rw-r--r--src/libs/utils/filepath.h3
-rw-r--r--src/libs/utils/fileutils.h2
-rw-r--r--src/plugins/docker/dockerdevice.cpp11
-rw-r--r--src/plugins/docker/dockerdevice.h1
-rw-r--r--src/plugins/projectexplorer/devicesupport/devicemanager.cpp12
-rw-r--r--src/plugins/projectexplorer/devicesupport/idevice.cpp5
-rw-r--r--src/plugins/projectexplorer/devicesupport/idevice.h1
8 files changed, 53 insertions, 0 deletions
diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp
index fd68683ace..ce6d0cc2cd 100644
--- a/src/libs/utils/filepath.cpp
+++ b/src/libs/utils/filepath.cpp
@@ -819,6 +819,24 @@ FilePath FilePath::symLinkTarget() const
return FilePath::fromString(info.symLinkTarget());
}
+FilePath FilePath::mapToGlobalPath() const
+{
+ if (needsDevice()) {
+ QTC_ASSERT(s_deviceHooks.mapToGlobalPath, return {});
+ return s_deviceHooks.mapToGlobalPath(*this);
+ }
+ return *this;
+}
+
+QString FilePath::mapToDevicePath() const
+{
+ if (needsDevice()) {
+ QTC_ASSERT(s_deviceHooks.mapToDevicePath, return {});
+ return s_deviceHooks.mapToDevicePath(*this);
+ }
+ return m_data;
+}
+
FilePath FilePath::withExecutableSuffix() const
{
FilePath res = *this;
diff --git a/src/libs/utils/filepath.h b/src/libs/utils/filepath.h
index 409421eaf5..21ef3e1243 100644
--- a/src/libs/utils/filepath.h
+++ b/src/libs/utils/filepath.h
@@ -161,6 +161,9 @@ public:
QDir::Filters filters = QDir::NoFilter,
QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags) const;
+ [[nodiscard]] FilePath mapToGlobalPath() const;
+ [[nodiscard]] QString mapToDevicePath() const;
+
// makes sure that capitalization of directories is canonical
// on Windows and macOS. This is rarely needed.
[[nodiscard]] FilePath normalizedPathName() const;
diff --git a/src/libs/utils/fileutils.h b/src/libs/utils/fileutils.h
index a92017f770..9fd0b6c2a0 100644
--- a/src/libs/utils/fileutils.h
+++ b/src/libs/utils/fileutils.h
@@ -78,6 +78,8 @@ public:
std::function<bool(const FilePath &, const FilePath &)> renameFile;
std::function<FilePath(const FilePath &, const QList<FilePath> &)> searchInPath;
std::function<FilePath(const FilePath &)> symLinkTarget;
+ std::function<FilePath(const FilePath &)> mapToGlobalPath;
+ std::function<QString(const FilePath &)> mapToDevicePath;
std::function<QList<FilePath>(const FilePath &, const QStringList &,
QDir::Filters, QDir::SortFlags)> dirEntries;
std::function<QByteArray(const FilePath &, qint64, qint64)> fileContents;
diff --git a/src/plugins/docker/dockerdevice.cpp b/src/plugins/docker/dockerdevice.cpp
index 638fb91db0..377b777d40 100644
--- a/src/plugins/docker/dockerdevice.cpp
+++ b/src/plugins/docker/dockerdevice.cpp
@@ -1069,6 +1069,17 @@ FilePath DockerDevice::mapToGlobalPath(const FilePath &pathOnDevice) const
return result;
}
+QString DockerDevice::mapToDevicePath(const Utils::FilePath &globalPath) const
+{
+ const FilePath normalized = globalPath.normalizedPathName();
+ QString path = normalized.path();
+ if (normalized.startsWithDriveLetter()) {
+ const QChar lowerDriveLetter = path.at(0).toLower();
+ path = '/' + lowerDriveLetter + path.mid(2); // strip C:
+ }
+ return path;
+}
+
bool DockerDevice::handlesFile(const FilePath &filePath) const
{
return filePath.scheme() == "docker" && filePath.host() == d->m_data.imageId;
diff --git a/src/plugins/docker/dockerdevice.h b/src/plugins/docker/dockerdevice.h
index ded9a93b06..c4d0efe703 100644
--- a/src/plugins/docker/dockerdevice.h
+++ b/src/plugins/docker/dockerdevice.h
@@ -76,6 +76,7 @@ public:
ProjectExplorer::DeviceEnvironmentFetcher::Ptr environmentFetcher() const override;
Utils::FilePath mapToGlobalPath(const Utils::FilePath &pathOnDevice) const override;
+ QString mapToDevicePath(const Utils::FilePath &globalPath) const override;
bool handlesFile(const Utils::FilePath &filePath) const override;
bool isExecutableFile(const Utils::FilePath &filePath) const override;
diff --git a/src/plugins/projectexplorer/devicesupport/devicemanager.cpp b/src/plugins/projectexplorer/devicesupport/devicemanager.cpp
index f7470cd079..1e671e5fe3 100644
--- a/src/plugins/projectexplorer/devicesupport/devicemanager.cpp
+++ b/src/plugins/projectexplorer/devicesupport/devicemanager.cpp
@@ -484,6 +484,18 @@ DeviceManager::DeviceManager(bool isInstance) : d(std::make_unique<DeviceManager
return device->symLinkTarget(filePath);
};
+ deviceHooks.mapToGlobalPath = [](const FilePath &filePath) {
+ auto device = DeviceManager::deviceForPath(filePath);
+ QTC_ASSERT(device, return FilePath{});
+ return device->mapToGlobalPath(filePath);
+ };
+
+ deviceHooks.mapToDevicePath = [](const FilePath &filePath) {
+ auto device = DeviceManager::deviceForPath(filePath);
+ QTC_ASSERT(device, return QString{});
+ return device->mapToDevicePath(filePath);
+ };
+
deviceHooks.dirEntries = [](const FilePath &filePath, const QStringList &nameFilters,
QDir::Filters filters, QDir::SortFlags sort) {
auto device = DeviceManager::deviceForPath(filePath);
diff --git a/src/plugins/projectexplorer/devicesupport/idevice.cpp b/src/plugins/projectexplorer/devicesupport/idevice.cpp
index 8c90a7fc14..f1bedcc441 100644
--- a/src/plugins/projectexplorer/devicesupport/idevice.cpp
+++ b/src/plugins/projectexplorer/devicesupport/idevice.cpp
@@ -212,6 +212,11 @@ FilePath IDevice::mapToGlobalPath(const FilePath &pathOnDevice) const
return pathOnDevice;
}
+QString IDevice::mapToDevicePath(const FilePath &globalPath) const
+{
+ return globalPath.path();
+}
+
bool IDevice::handlesFile(const FilePath &filePath) const
{
Q_UNUSED(filePath);
diff --git a/src/plugins/projectexplorer/devicesupport/idevice.h b/src/plugins/projectexplorer/devicesupport/idevice.h
index 873eb380bb..56bdbb5bd2 100644
--- a/src/plugins/projectexplorer/devicesupport/idevice.h
+++ b/src/plugins/projectexplorer/devicesupport/idevice.h
@@ -237,6 +237,7 @@ public:
bool isAnyUnixDevice() const;
virtual Utils::FilePath mapToGlobalPath(const Utils::FilePath &pathOnDevice) const;
+ virtual QString mapToDevicePath(const Utils::FilePath &globalPath) const;
virtual bool handlesFile(const Utils::FilePath &filePath) const;
virtual bool isExecutableFile(const Utils::FilePath &filePath) const;