Utils: Remove offset parameter from writeFileContents

It never worked and was not used, so remove it for now.

Change-Id: If271bf83e1c766cc31fdb24dbab9eac228fda0a2
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Marcus Tillmanns
2024-02-22 10:42:42 +01:00
parent e678da9934
commit 0aa54364f8
4 changed files with 9 additions and 22 deletions

View File

@@ -314,12 +314,10 @@ expected_str<QByteArray> DeviceFileAccess::fileContents(const FilePath &filePath
} }
expected_str<qint64> DeviceFileAccess::writeFileContents(const FilePath &filePath, expected_str<qint64> DeviceFileAccess::writeFileContents(const FilePath &filePath,
const QByteArray &data, const QByteArray &data) const
qint64 offset) const
{ {
Q_UNUSED(filePath) Q_UNUSED(filePath)
Q_UNUSED(data) Q_UNUSED(data)
Q_UNUSED(offset)
QTC_CHECK(false); QTC_CHECK(false);
return make_unexpected( return make_unexpected(
Tr::tr("writeFileContents is not implemented for \"%1\".").arg(filePath.toUserOutput())); Tr::tr("writeFileContents is not implemented for \"%1\".").arg(filePath.toUserOutput()));
@@ -738,8 +736,7 @@ expected_str<QByteArray> DesktopDeviceFileAccess::fileContents(const FilePath &f
} }
expected_str<qint64> DesktopDeviceFileAccess::writeFileContents(const FilePath &filePath, expected_str<qint64> DesktopDeviceFileAccess::writeFileContents(const FilePath &filePath,
const QByteArray &data, const QByteArray &data) const
qint64 offset) const
{ {
QFile file(filePath.path()); QFile file(filePath.path());
const bool isOpened = file.open(QFile::WriteOnly | QFile::Truncate); const bool isOpened = file.open(QFile::WriteOnly | QFile::Truncate);
@@ -747,8 +744,6 @@ expected_str<qint64> DesktopDeviceFileAccess::writeFileContents(const FilePath &
return make_unexpected( return make_unexpected(
Tr::tr("Could not open file \"%1\" for writing.").arg(filePath.toUserOutput())); Tr::tr("Could not open file \"%1\" for writing.").arg(filePath.toUserOutput()));
if (offset != 0)
file.seek(offset);
qint64 res = file.write(data); qint64 res = file.write(data);
if (res != data.size()) if (res != data.size())
return make_unexpected( return make_unexpected(
@@ -1088,17 +1083,12 @@ expected_str<QByteArray> UnixDeviceFileAccess::fileContents(const FilePath &file
} }
expected_str<qint64> UnixDeviceFileAccess::writeFileContents(const FilePath &filePath, expected_str<qint64> UnixDeviceFileAccess::writeFileContents(const FilePath &filePath,
const QByteArray &data, const QByteArray &data) const
qint64 offset) const
{ {
if (disconnected()) if (disconnected())
return make_unexpected_disconnected(); return make_unexpected_disconnected();
QStringList args = {"of=" + filePath.path()}; QStringList args = {"of=" + filePath.path()};
if (offset != 0) {
args.append("bs=1");
args.append(QString("seek=%1").arg(offset));
}
RunResult result = runInShell({"dd", args, OsType::OsTypeLinux}, data); RunResult result = runInShell({"dd", args, OsType::OsTypeLinux}, data);
if (result.exitCode != 0) { if (result.exitCode != 0) {

View File

@@ -69,8 +69,7 @@ protected:
qint64 offset) const; qint64 offset) const;
virtual expected_str<qint64> writeFileContents(const FilePath &filePath, virtual expected_str<qint64> writeFileContents(const FilePath &filePath,
const QByteArray &data, const QByteArray &data) const;
qint64 offset) const;
virtual expected_str<FilePath> createTempFile(const FilePath &filePath); virtual expected_str<FilePath> createTempFile(const FilePath &filePath);
}; };
@@ -125,8 +124,7 @@ protected:
qint64 limit, qint64 limit,
qint64 offset) const override; qint64 offset) const override;
expected_str<qint64> writeFileContents(const FilePath &filePath, expected_str<qint64> writeFileContents(const FilePath &filePath,
const QByteArray &data, const QByteArray &data) const override;
qint64 offset) const override;
expected_str<FilePath> createTempFile(const FilePath &filePath) override; expected_str<FilePath> createTempFile(const FilePath &filePath) override;
@@ -178,8 +176,7 @@ protected:
qint64 limit, qint64 limit,
qint64 offset) const override; qint64 offset) const override;
expected_str<qint64> writeFileContents(const FilePath &filePath, expected_str<qint64> writeFileContents(const FilePath &filePath,
const QByteArray &data, const QByteArray &data) const override;
qint64 offset) const override;
expected_str<FilePath> createTempFile(const FilePath &filePath) override; expected_str<FilePath> createTempFile(const FilePath &filePath) override;

View File

@@ -655,9 +655,9 @@ bool FilePath::ensureReachable(const FilePath &other) const
return false; return false;
} }
expected_str<qint64> FilePath::writeFileContents(const QByteArray &data, qint64 offset) const expected_str<qint64> FilePath::writeFileContents(const QByteArray &data) const
{ {
return fileAccess()->writeFileContents(*this, data, offset); return fileAccess()->writeFileContents(*this, data);
} }
FileStreamHandle FilePath::asyncCopy(const FilePath &target, QObject *context, FileStreamHandle FilePath::asyncCopy(const FilePath &target, QObject *context,

View File

@@ -139,7 +139,7 @@ public:
FilePaths dirEntries(const FileFilter &filter, QDir::SortFlags sort = QDir::NoSort) const; FilePaths dirEntries(const FileFilter &filter, QDir::SortFlags sort = QDir::NoSort) const;
FilePaths dirEntries(QDir::Filters filters) const; FilePaths dirEntries(QDir::Filters filters) const;
expected_str<QByteArray> fileContents(qint64 maxSize = -1, qint64 offset = 0) const; expected_str<QByteArray> fileContents(qint64 maxSize = -1, qint64 offset = 0) const;
expected_str<qint64> writeFileContents(const QByteArray &data, qint64 offset = 0) const; expected_str<qint64> writeFileContents(const QByteArray &data) const;
FilePathInfo filePathInfo() const; FilePathInfo filePathInfo() const;
[[nodiscard]] FilePath operator/(const QString &str) const; [[nodiscard]] FilePath operator/(const QString &str) const;