Fix written time stamp in QML cache files for QRC sources

For loading and verification we compare against the time stamp of the
executable, so we should do the same thing when generating the cache
data.

Task-number: QTBUG-55926
Change-Id: If5922e76b8ae86185f6eacb6aeeb5c3afbc1f8d5
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
This commit is contained in:
Simon Hausmann 2016-09-12 16:48:59 +02:00
parent 330663c7b6
commit a94452b199
2 changed files with 18 additions and 3 deletions

View File

@ -3102,8 +3102,14 @@ QByteArray QQmlDataBlob::Data::readAll(QString *error, qint64 *sourceTimeStamp)
*error = f.errorString();
return QByteArray();
}
if (sourceTimeStamp)
*sourceTimeStamp = QFileInfo(f).lastModified().toMSecsSinceEpoch();
if (sourceTimeStamp) {
QDateTime timeStamp = QFileInfo(f).lastModified();
// Files from the resource system do not have any time stamps, so fall back to the application
// executable.
if (!timeStamp.isValid())
timeStamp = QFileInfo(QCoreApplication::applicationFilePath()).lastModified();
*sourceTimeStamp = timeStamp.toMSecsSinceEpoch();
}
QByteArray data(f.size(), Qt::Uninitialized);
if (f.read(data.data(), data.length()) != data.length()) {
*error = f.errorString();

View File

@ -554,7 +554,16 @@ void tst_qmldiskcache::cacheResources()
QCOMPARE(obj->property("value").toInt(), 20);
}
QCOMPARE(QDir(qmlCacheDirectory).entryList(QDir::NoDotAndDotDot | QDir::Files).count(), 1);
const QStringList entries = QDir(qmlCacheDirectory).entryList(QDir::NoDotAndDotDot | QDir::Files);
QCOMPARE(entries.count(), 1);
{
QFile cacheFile(qmlCacheDirectory + QLatin1Char('/') + entries.constFirst());
QVERIFY2(cacheFile.open(QIODevice::ReadOnly), qPrintable(cacheFile.errorString()));
QV4::CompiledData::Unit unit;
QVERIFY(cacheFile.read(reinterpret_cast<char *>(&unit), sizeof(unit)) == sizeof(unit));
QCOMPARE(qint64(unit.sourceTimeStamp), QFileInfo(QCoreApplication::applicationFilePath()).lastModified().toMSecsSinceEpoch());
}
}
QTEST_MAIN(tst_qmldiskcache)