aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorhjk <hjk@qt.io>2022-10-10 17:11:51 +0200
committerhjk <hjk@qt.io>2022-10-10 16:08:28 +0000
commit2e38cb68489326142f78d3c5c022b5a2ae866762 (patch)
tree74fc63156276f66e915b4cb9b2354868cb5f243f /src/plugins
parent0c2a86b63f928a416b256e110330cef87fec85ba (diff)
Utils: Add an offset parameter to the content writing FilePath function
Use QFile::seek to implement locally and a dd seek based poor man's implementation on RL and docker. Change-Id: I241d1c34c00e991845d132ad8edefa1377ba1311 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/docker/dockerdevice.cpp11
-rw-r--r--src/plugins/docker/dockerdevice.h4
-rw-r--r--src/plugins/projectexplorer/devicesupport/desktopdevice.cpp6
-rw-r--r--src/plugins/projectexplorer/devicesupport/desktopdevice.h4
-rw-r--r--src/plugins/projectexplorer/devicesupport/devicemanager.cpp6
-rw-r--r--src/plugins/projectexplorer/devicesupport/idevice.cpp8
-rw-r--r--src/plugins/projectexplorer/devicesupport/idevice.h7
-rw-r--r--src/plugins/remotelinux/linuxdevice.cpp11
-rw-r--r--src/plugins/remotelinux/linuxdevice.h4
9 files changed, 45 insertions, 16 deletions
diff --git a/src/plugins/docker/dockerdevice.cpp b/src/plugins/docker/dockerdevice.cpp
index 8ab4bb9f8e6..38a30aa76f3 100644
--- a/src/plugins/docker/dockerdevice.cpp
+++ b/src/plugins/docker/dockerdevice.cpp
@@ -910,10 +910,17 @@ std::optional<QByteArray> DockerDevice::fileContents(const FilePath &filePath,
return d->fileContents(filePath, limit, offset);
}
-bool DockerDevice::writeFileContents(const FilePath &filePath, const QByteArray &data) const
+bool DockerDevice::writeFileContents(const FilePath &filePath,
+ const QByteArray &data,
+ qint64 offset) const
{
QTC_ASSERT(handlesFile(filePath), return {});
- return d->runInShellSuccess({"dd", {"of=" + filePath.path()}}, data);
+ CommandLine cmd({"dd", {"of=" + filePath.path()}});
+ if (offset != 0) {
+ cmd.addArg("bs=1");
+ cmd.addArg(QString("seek=%1").arg(offset));
+ }
+ return d->runInShellSuccess(cmd, data);
}
Environment DockerDevice::systemEnvironment() const
diff --git a/src/plugins/docker/dockerdevice.h b/src/plugins/docker/dockerdevice.h
index 7de2a762829..4e7840b9282 100644
--- a/src/plugins/docker/dockerdevice.h
+++ b/src/plugins/docker/dockerdevice.h
@@ -105,7 +105,9 @@ public:
std::optional<QByteArray> fileContents(const Utils::FilePath &filePath,
qint64 limit,
qint64 offset) const override;
- bool writeFileContents(const Utils::FilePath &filePath, const QByteArray &data) const override;
+ bool writeFileContents(const Utils::FilePath &filePath,
+ const QByteArray &data,
+ qint64 offset) const override;
QDateTime lastModified(const Utils::FilePath &filePath) const override;
qint64 fileSize(const Utils::FilePath &filePath) const override;
QFileDevice::Permissions permissions(const Utils::FilePath &filePath) const override;
diff --git a/src/plugins/projectexplorer/devicesupport/desktopdevice.cpp b/src/plugins/projectexplorer/devicesupport/desktopdevice.cpp
index baee2cd84eb..105e80e34f1 100644
--- a/src/plugins/projectexplorer/devicesupport/desktopdevice.cpp
+++ b/src/plugins/projectexplorer/devicesupport/desktopdevice.cpp
@@ -278,10 +278,12 @@ std::optional<QByteArray> DesktopDevice::fileContents(const FilePath &filePath,
return filePath.fileContents(limit, offset);
}
-bool DesktopDevice::writeFileContents(const Utils::FilePath &filePath, const QByteArray &data) const
+bool DesktopDevice::writeFileContents(const FilePath &filePath,
+ const QByteArray &data,
+ qint64 offset) const
{
QTC_ASSERT(handlesFile(filePath), return {});
- return filePath.writeFileContents(data);
+ return filePath.writeFileContents(data, offset);
}
} // namespace ProjectExplorer
diff --git a/src/plugins/projectexplorer/devicesupport/desktopdevice.h b/src/plugins/projectexplorer/devicesupport/desktopdevice.h
index b310c73b7d3..a2a17237ac3 100644
--- a/src/plugins/projectexplorer/devicesupport/desktopdevice.h
+++ b/src/plugins/projectexplorer/devicesupport/desktopdevice.h
@@ -56,7 +56,9 @@ public:
std::optional<QByteArray> fileContents(const Utils::FilePath &filePath,
qint64 limit,
qint64 offset) const override;
- bool writeFileContents(const Utils::FilePath &filePath, const QByteArray &data) const override;
+ bool writeFileContents(const Utils::FilePath &filePath,
+ const QByteArray &data,
+ qint64 offset) const override;
qint64 fileSize(const Utils::FilePath &filePath) const override;
QFile::Permissions permissions(const Utils::FilePath &filePath) const override;
bool setPermissions(const Utils::FilePath &filePath, QFile::Permissions) const override;
diff --git a/src/plugins/projectexplorer/devicesupport/devicemanager.cpp b/src/plugins/projectexplorer/devicesupport/devicemanager.cpp
index c0ae7a1726e..febcc6436eb 100644
--- a/src/plugins/projectexplorer/devicesupport/devicemanager.cpp
+++ b/src/plugins/projectexplorer/devicesupport/devicemanager.cpp
@@ -544,10 +544,12 @@ DeviceManager::DeviceManager(bool isInstance) : d(std::make_unique<DeviceManager
device->asyncFileContents(cont, filePath, maxSize, offset);
};
- deviceHooks.writeFileContents = [](const FilePath &filePath, const QByteArray &data) {
+ deviceHooks.writeFileContents = [](const FilePath &filePath,
+ const QByteArray &data,
+ qint64 offset) {
auto device = DeviceManager::deviceForPath(filePath);
QTC_ASSERT(device, return false);
- return device->writeFileContents(filePath, data);
+ return device->writeFileContents(filePath, data, offset);
};
deviceHooks.lastModified = [](const FilePath &filePath) {
diff --git a/src/plugins/projectexplorer/devicesupport/idevice.cpp b/src/plugins/projectexplorer/devicesupport/idevice.cpp
index 7b723a2fcee..9c391de5aed 100644
--- a/src/plugins/projectexplorer/devicesupport/idevice.cpp
+++ b/src/plugins/projectexplorer/devicesupport/idevice.cpp
@@ -384,19 +384,21 @@ void IDevice::asyncFileContents(const Continuation<std::optional<QByteArray>> &c
cont(fileContents(filePath, limit, offset));
}
-bool IDevice::writeFileContents(const FilePath &filePath, const QByteArray &data) const
+bool IDevice::writeFileContents(const FilePath &filePath, const QByteArray &data, qint64 offset) const
{
Q_UNUSED(filePath);
Q_UNUSED(data);
+ Q_UNUSED(offset);
QTC_CHECK(false);
return {};
}
void IDevice::asyncWriteFileContents(const Continuation<bool> &cont,
const FilePath &filePath,
- const QByteArray &data) const
+ const QByteArray &data,
+ qint64 offset) const
{
- cont(writeFileContents(filePath, data));
+ cont(writeFileContents(filePath, data, offset));
}
QDateTime IDevice::lastModified(const FilePath &filePath) const
diff --git a/src/plugins/projectexplorer/devicesupport/idevice.h b/src/plugins/projectexplorer/devicesupport/idevice.h
index 3e144a9e502..58d0892fc65 100644
--- a/src/plugins/projectexplorer/devicesupport/idevice.h
+++ b/src/plugins/projectexplorer/devicesupport/idevice.h
@@ -243,7 +243,9 @@ public:
virtual std::optional<QByteArray> fileContents(const Utils::FilePath &filePath,
qint64 limit,
qint64 offset) const;
- virtual bool writeFileContents(const Utils::FilePath &filePath, const QByteArray &data) const;
+ virtual bool writeFileContents(const Utils::FilePath &filePath,
+ const QByteArray &data,
+ qint64 offset) const;
virtual QDateTime lastModified(const Utils::FilePath &filePath) const;
virtual QFile::Permissions permissions(const Utils::FilePath &filePath) const;
virtual bool setPermissions(const Utils::FilePath &filePath, QFile::Permissions) const;
@@ -262,7 +264,8 @@ public:
qint64 offset) const;
virtual void asyncWriteFileContents(const Continuation<bool> &cont,
const Utils::FilePath &filePath,
- const QByteArray &data) const;
+ const QByteArray &data,
+ qint64 offset) const;
virtual bool ensureReachable(const Utils::FilePath &other) const;
diff --git a/src/plugins/remotelinux/linuxdevice.cpp b/src/plugins/remotelinux/linuxdevice.cpp
index cf7fe54810a..2d2d8684d69 100644
--- a/src/plugins/remotelinux/linuxdevice.cpp
+++ b/src/plugins/remotelinux/linuxdevice.cpp
@@ -1318,10 +1318,17 @@ std::optional<QByteArray> LinuxDevice::fileContents(const FilePath &filePath,
return result.stdOut;
}
-bool LinuxDevice::writeFileContents(const FilePath &filePath, const QByteArray &data) const
+bool LinuxDevice::writeFileContents(const FilePath &filePath,
+ const QByteArray &data,
+ qint64 offset) const
{
QTC_ASSERT(handlesFile(filePath), return {});
- return d->runInShellSuccess({"dd", {"of=" + filePath.path()}}, data);
+ CommandLine cmd({"dd", {"of=" + filePath.path()}});
+ if (offset != 0) {
+ cmd.addArg("bs=1");
+ cmd.addArg(QString("seek=%1").arg(offset));
+ }
+ return d->runInShellSuccess(cmd, data);
}
static FilePaths dirsToCreate(const FilesToTransfer &files)
diff --git a/src/plugins/remotelinux/linuxdevice.h b/src/plugins/remotelinux/linuxdevice.h
index 0d4748cb308..1cecc12f2e7 100644
--- a/src/plugins/remotelinux/linuxdevice.h
+++ b/src/plugins/remotelinux/linuxdevice.h
@@ -58,7 +58,9 @@ public:
std::optional<QByteArray> fileContents(const Utils::FilePath &filePath,
qint64 limit,
qint64 offset) const override;
- bool writeFileContents(const Utils::FilePath &filePath, const QByteArray &data) const override;
+ bool writeFileContents(const Utils::FilePath &filePath,
+ const QByteArray &data,
+ qint64 offset) const override;
QDateTime lastModified(const Utils::FilePath &filePath) const override;
Utils::ProcessInterface *createProcessInterface() const override;
ProjectExplorer::FileTransferInterface *createFileTransferInterface(