Utils: Implement FilePath::writeFileContents()

Including a docker version of it.

Change-Id: Ib2ac6073cc2b39818fb77a7d9d608386f9d17285
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2021-06-15 18:29:51 +02:00
parent fee82ed2c2
commit e3c03fd3c5
7 changed files with 42 additions and 0 deletions

View File

@@ -957,6 +957,19 @@ QByteArray FilePath::fileContents(int maxSize) const
return f.readAll();
}
bool FilePath::writeFileContents(const QByteArray &data) const
{
if (needsDevice()) {
QTC_ASSERT(s_deviceHooks.writeFileContents, return {});
return s_deviceHooks.writeFileContents(*this, data);
}
QFile file(path());
QTC_ASSERT(file.open(QFile::WriteOnly | QFile::Truncate), return false);
qint64 res = file.write(data);
return res == data.size();
}
bool FilePath::needsDevice() const
{
return !m_scheme.isEmpty();