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>
This commit is contained in:
hjk
2022-10-10 17:11:51 +02:00
parent 0c2a86b63f
commit 2e38cb6848
12 changed files with 65 additions and 27 deletions

View File

@@ -586,28 +586,32 @@ void FilePath::asyncFileContents(const Continuation<const std::optional<QByteArr
cont(fileContents(maxSize, offset));
}
bool FilePath::writeFileContents(const QByteArray &data) const
bool FilePath::writeFileContents(const QByteArray &data, qint64 offset) const
{
if (needsDevice()) {
QTC_ASSERT(s_deviceHooks.writeFileContents, return {});
return s_deviceHooks.writeFileContents(*this, data);
return s_deviceHooks.writeFileContents(*this, data, offset);
}
QFile file(path());
QTC_ASSERT(file.open(QFile::WriteOnly | QFile::Truncate), return false);
if (offset != 0)
file.seek(offset);
qint64 res = file.write(data);
return res == data.size();
}
void FilePath::asyncWriteFileContents(const Continuation<bool> &cont, const QByteArray &data) const
void FilePath::asyncWriteFileContents(const Continuation<bool> &cont,
const QByteArray &data,
qint64 offset) const
{
if (needsDevice()) {
QTC_ASSERT(s_deviceHooks.asyncWriteFileContents, return);
s_deviceHooks.asyncWriteFileContents(cont, *this, data);
s_deviceHooks.asyncWriteFileContents(cont, *this, data, offset);
return;
}
cont(writeFileContents(data));
cont(writeFileContents(data, offset));
}
bool FilePath::needsDevice() const