summaryrefslogtreecommitdiffstats
path: root/qmake/library/qmakevfs.cpp
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@qt.io>2016-10-28 20:10:40 +0200
committerOswald Buddenhagen <oswald.buddenhagen@qt.io>2018-03-29 18:14:58 +0000
commite2de837198884b64345f746ef257e6d83bffa571 (patch)
tree18385813951e64b769d32bb35e331cdf673c30a8 /qmake/library/qmakevfs.cpp
parentfe5f2a235cd51020c04570ec3f37070f6be7a1a3 (diff)
qmake: let QMakeVfs::readFile() report ENOFILE explicitly
when the QFile object is already constructed, querying whether the file exists is actually cheap, so do it right away instead of later on demand. that makes the calling code a bit cleaner. fwiw, that we need to explicitly query the file's existence at all is a result of QFile's completely useless error "codes" (which merely say which function failed, as if the caller would not know). Change-Id: Ifec39d05b1713d8128046f679287e510f10e45dc Reviewed-by: Tobias Hunger <tobias.hunger@qt.io> (cherry picked from qtcreator/5ba32e3484ead2e35cc7732dcd59a97e7459dbfd) Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'qmake/library/qmakevfs.cpp')
-rw-r--r--qmake/library/qmakevfs.cpp21
1 files changed, 11 insertions, 10 deletions
diff --git a/qmake/library/qmakevfs.cpp b/qmake/library/qmakevfs.cpp
index 5aa9ec9299..7631723b1b 100644
--- a/qmake/library/qmakevfs.cpp
+++ b/qmake/library/qmakevfs.cpp
@@ -100,7 +100,7 @@ bool QMakeVfs::writeFile(const QString &fn, QIODevice::OpenMode mode, bool exe,
#endif
}
-bool QMakeVfs::readFile(const QString &fn, QString *contents, QString *errStr)
+QMakeVfs::ReadResult QMakeVfs::readFile(const QString &fn, QString *contents, QString *errStr)
{
#ifndef PROEVALUATOR_FULL
# ifdef PROEVALUATOR_THREAD_SAFE
@@ -110,25 +110,26 @@ bool QMakeVfs::readFile(const QString &fn, QString *contents, QString *errStr)
if (it != m_files.constEnd()) {
if (it->constData() == m_magicMissing.constData()) {
*errStr = fL1S("No such file or directory");
- return false;
+ return ReadNotFound;
}
if (it->constData() != m_magicExisting.constData()) {
*contents = *it;
- return true;
+ return ReadOk;
}
}
#endif
QFile file(fn);
if (!file.open(QIODevice::ReadOnly)) {
+ if (!file.exists()) {
#ifndef PROEVALUATOR_FULL
- if (!IoUtils::exists(fn)) {
m_files[fn] = m_magicMissing;
- *errStr = fL1S("No such file or directory");
- } else
#endif
- *errStr = file.errorString();
- return false;
+ *errStr = fL1S("No such file or directory");
+ return ReadNotFound;
+ }
+ *errStr = file.errorString();
+ return ReadOtherError;
}
#ifndef PROEVALUATOR_FULL
m_files[fn] = m_magicExisting;
@@ -138,10 +139,10 @@ bool QMakeVfs::readFile(const QString &fn, QString *contents, QString *errStr)
if (bcont.startsWith("\xef\xbb\xbf")) {
// UTF-8 BOM will cause subtle errors
*errStr = fL1S("Unexpected UTF-8 BOM");
- return false;
+ return ReadOtherError;
}
*contents = QString::fromLocal8Bit(bcont);
- return true;
+ return ReadOk;
}
bool QMakeVfs::exists(const QString &fn)