summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhjk <hjk@qt.io>2021-06-01 09:40:17 +0200
committerhjk <hjk@qt.io>2021-06-07 12:16:38 +0000
commita7cd9bda3a98b9a8053720ae71914be912f728ac (patch)
treec521eaab3e85b15932f6bd769aba0afbf2045f23
parent422409bf261c3653f98b4fc3163829eee393d6ef (diff)
downloadqt-creator-a7cd9bda3a98b9a8053720ae71914be912f728ac.tar.gz
ProjectExplorer: Implement (Docker)Device::exists(filePath)
While the original plan was to use more specific functions like 'isReadableFile' to cut down the number of accesses, it is unrealistic to re-write all occurrences in reasonable time. So make the basic building blocks accessible, too. Change-Id: I2586ebd19e1e7ae2c884fd2a4180869421293e3a Reviewed-by: David Schulz <david.schulz@qt.io>
-rw-r--r--src/libs/utils/fileutils.cpp5
-rw-r--r--src/libs/utils/fileutils.h1
-rw-r--r--src/plugins/docker/dockerdevice.cpp16
-rw-r--r--src/plugins/docker/dockerdevice.h1
-rw-r--r--src/plugins/projectexplorer/devicesupport/devicemanager.cpp6
-rw-r--r--src/plugins/projectexplorer/devicesupport/idevice.cpp7
-rw-r--r--src/plugins/projectexplorer/devicesupport/idevice.h1
7 files changed, 36 insertions, 1 deletions
diff --git a/src/libs/utils/fileutils.cpp b/src/libs/utils/fileutils.cpp
index 71bfd96aff..a735bc3fa1 100644
--- a/src/libs/utils/fileutils.cpp
+++ b/src/libs/utils/fileutils.cpp
@@ -832,7 +832,10 @@ void FilePath::setHost(const QString &host)
/// FilePath exists.
bool FilePath::exists() const
{
- QTC_ASSERT(!needsDevice(), return false);
+ if (needsDevice()) {
+ QTC_ASSERT(s_deviceHooks.exists, return false);
+ return s_deviceHooks.exists(*this);
+ }
return !isEmpty() && QFileInfo::exists(m_data);
}
diff --git a/src/libs/utils/fileutils.h b/src/libs/utils/fileutils.h
index 431e9ec0c6..b2400c5bc2 100644
--- a/src/libs/utils/fileutils.h
+++ b/src/libs/utils/fileutils.h
@@ -75,6 +75,7 @@ public:
std::function<bool(const FilePath &)> isWritableDir;
std::function<bool(const FilePath &)> ensureWritableDir;
std::function<bool(const FilePath &)> createDir;
+ std::function<bool(const FilePath &)> exists;
std::function<QList<FilePath>(const FilePath &, const QStringList &, QDir::Filters)> dirEntries;
std::function<QByteArray(const FilePath &, int)> fileContents;
};
diff --git a/src/plugins/docker/dockerdevice.cpp b/src/plugins/docker/dockerdevice.cpp
index 92aa80a74a..5a89d915d9 100644
--- a/src/plugins/docker/dockerdevice.cpp
+++ b/src/plugins/docker/dockerdevice.cpp
@@ -688,6 +688,22 @@ bool DockerDevice::createDirectory(const FilePath &filePath) const
return exitCode == 0;
}
+bool DockerDevice::exists(const FilePath &filePath) const
+{
+ QTC_ASSERT(handlesFile(filePath), return false);
+ tryCreateLocalFileAccess();
+ if (hasLocalFileAccess()) {
+ const FilePath localAccess = mapToLocalAccess(filePath);
+ const bool res = localAccess.exists();
+ LOG("Exists? " << filePath.toUserOutput() << localAccess.toUserOutput() << res);
+ return res;
+ }
+ const QString path = filePath.path();
+ const CommandLine cmd("test", {"-e", path});
+ const int exitCode = d->runSynchronously(cmd);
+ return exitCode == 0;
+}
+
QList<FilePath> DockerDevice::directoryEntries(const FilePath &filePath,
const QStringList &nameFilters,
QDir::Filters filters) const
diff --git a/src/plugins/docker/dockerdevice.h b/src/plugins/docker/dockerdevice.h
index ee9b6a90eb..572af3d628 100644
--- a/src/plugins/docker/dockerdevice.h
+++ b/src/plugins/docker/dockerdevice.h
@@ -78,6 +78,7 @@ public:
bool isReadableDirectory(const Utils::FilePath &filePath) const override;
bool isWritableDirectory(const Utils::FilePath &filePath) const override;
bool createDirectory(const Utils::FilePath &filePath) const override;
+ bool exists(const Utils::FilePath &filePath) const override;
QList<Utils::FilePath> directoryEntries(const Utils::FilePath &filePath,
const QStringList &nameFilters,
QDir::Filters filters) const override;
diff --git a/src/plugins/projectexplorer/devicesupport/devicemanager.cpp b/src/plugins/projectexplorer/devicesupport/devicemanager.cpp
index 2f02277358..cc41b13188 100644
--- a/src/plugins/projectexplorer/devicesupport/devicemanager.cpp
+++ b/src/plugins/projectexplorer/devicesupport/devicemanager.cpp
@@ -401,6 +401,12 @@ DeviceManager::DeviceManager(bool isInstance) : d(std::make_unique<DeviceManager
return device->createDirectory(filePath);
};
+ deviceHooks.exists = [](const FilePath &filePath) {
+ auto device = DeviceManager::deviceForPath(filePath);
+ QTC_ASSERT(device, return false);
+ return device->exists(filePath);
+ };
+
deviceHooks.dirEntries = [](const FilePath &filePath,
const QStringList &nameFilters, QDir::Filters filters) {
auto device = DeviceManager::deviceForPath(filePath);
diff --git a/src/plugins/projectexplorer/devicesupport/idevice.cpp b/src/plugins/projectexplorer/devicesupport/idevice.cpp
index dab6d5618f..c9b3338097 100644
--- a/src/plugins/projectexplorer/devicesupport/idevice.cpp
+++ b/src/plugins/projectexplorer/devicesupport/idevice.cpp
@@ -259,6 +259,13 @@ bool IDevice::createDirectory(const Utils::FilePath &filePath) const
return false;
}
+bool IDevice::exists(const Utils::FilePath &filePath) const
+{
+ Q_UNUSED(filePath);
+ QTC_CHECK(false);
+ return false;
+}
+
QList<FilePath> IDevice::directoryEntries(const FilePath &filePath,
const QStringList &nameFilters,
QDir::Filters filters) const
diff --git a/src/plugins/projectexplorer/devicesupport/idevice.h b/src/plugins/projectexplorer/devicesupport/idevice.h
index 9c62851758..61f9a982da 100644
--- a/src/plugins/projectexplorer/devicesupport/idevice.h
+++ b/src/plugins/projectexplorer/devicesupport/idevice.h
@@ -242,6 +242,7 @@ public:
virtual bool isWritableDirectory(const Utils::FilePath &filePath) const;
virtual bool ensureWritableDirectory(const Utils::FilePath &filePath) const;
virtual bool createDirectory(const Utils::FilePath &filePath) const;
+ virtual bool exists(const Utils::FilePath &filePath) const;
virtual QList<Utils::FilePath> directoryEntries(const Utils::FilePath &filePath,
const QStringList &nameFilters,
QDir::Filters filters) const;