forked from qt-creator/qt-creator
FilePath: Return optional bytearray for file contents
For differentiating between "error" and "empty file". Change-Id: I2c019ceac625e7be3180afa4d47ae3a24df91c1d Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -58,8 +58,12 @@ bool FileReader::fetch(const FilePath &filePath, QIODevice::OpenMode mode)
|
||||
QTC_ASSERT(!(mode & ~(QIODevice::ReadOnly | QIODevice::Text)), return false);
|
||||
|
||||
if (filePath.needsDevice()) {
|
||||
// TODO: add error handling to FilePath::fileContents
|
||||
m_data = filePath.fileContents();
|
||||
const std::optional<QByteArray> contents = filePath.fileContents();
|
||||
if (!contents) {
|
||||
m_errorString = tr("Cannot read %1").arg(filePath.toUserOutput());
|
||||
return false;
|
||||
}
|
||||
m_data = *contents;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -668,8 +672,8 @@ bool FileUtils::copyIfDifferent(const FilePath &srcFilePath, const FilePath &tgt
|
||||
const QDateTime srcModified = srcFilePath.lastModified();
|
||||
const QDateTime tgtModified = tgtFilePath.lastModified();
|
||||
if (srcModified == tgtModified) {
|
||||
const QByteArray srcContents = srcFilePath.fileContents();
|
||||
const QByteArray tgtContents = srcFilePath.fileContents();
|
||||
const std::optional<QByteArray> srcContents = srcFilePath.fileContents();
|
||||
const std::optional<QByteArray> tgtContents = srcFilePath.fileContents();
|
||||
if (srcContents == tgtContents)
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user