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:
Eike Ziller
2022-09-09 13:48:08 +02:00
parent 28349c1b08
commit 2c51e4bc17
22 changed files with 84 additions and 49 deletions

View File

@@ -859,9 +859,10 @@ static bool findNewQmlLibraryInPath(const Utils::FilePath &path,
}
// found a new library!
if (!qmldirFile.isReadableFile())
const std::optional<QByteArray> contents = qmldirFile.fileContents();
if (!contents)
return false;
QString qmldirData = QString::fromUtf8(qmldirFile.fileContents());
QString qmldirData = QString::fromUtf8(*contents);
QmlDirParser qmldirParser;
qmldirParser.parse(qmldirData);
@@ -968,8 +969,9 @@ void ModelManagerInterface::parseLoop(QSet<Utils::FilePath> &scannedPaths,
contents = entry.first;
documentRevision = entry.second;
} else {
if (fileName.isReadableFile()) {
QTextStream ins(fileName.fileContents());
const std::optional<QByteArray> fileContents = fileName.fileContents();
if (fileContents) {
QTextStream ins(*fileContents);
contents = ins.readAll();
} else {
continue;