diff options
author | Katja Marttila <katja.marttila@qt.io> | 2024-03-14 15:31:07 +0200 |
---|---|---|
committer | Katja Marttila <katja.marttila@qt.io> | 2024-03-22 13:28:58 +0200 |
commit | 240d0990a52ddadca265b3d0286d9dce69689f08 (patch) | |
tree | 1b7bbc5d4a83141332b48cb963fd3341dff27943 /src | |
parent | 09d5bbe279b1ae3541deaf22e01df4ad15136256 (diff) |
Speed up cache validation
Cache validation takes some time especially in Windows, mostly the time
is spent in opening the files for the integrity check. Instead of
writing the sha checksum to file to verify the integrity, name the file
itself with the sha checksum. Then it is enough to check if the correct
file exists and we don't need to open the file.
Task-number: QTIFW-3328
Change-Id: I36835d783ccf2f6aad8c83e14ec19cbdfc6db71e
Reviewed-by: Arttu Tarkiainen <arttu.tarkiainen@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/installer/metadata.cpp | 12 | ||||
-rw-r--r-- | src/libs/installer/metadatajob_p.h | 6 |
2 files changed, 5 insertions, 13 deletions
diff --git a/src/libs/installer/metadata.cpp b/src/libs/installer/metadata.cpp index 3fca6d098..2eccb020e 100644 --- a/src/libs/installer/metadata.cpp +++ b/src/libs/installer/metadata.cpp @@ -78,20 +78,12 @@ static bool verifyFileIntegrityFromElement(const QDomElement &element, const QSt if (!testChecksum) continue; - QFile hashFile(file.fileName() + QLatin1String(".sha1")); - if (!hashFile.open(QIODevice::ReadOnly)) { - qCWarning(QInstaller::lcInstallerInstallLog) - << "Cannot open" << hashFile.fileName() - << "for reading:" << hashFile.errorString(); - return false; - } - QCryptographicHash hash(QCryptographicHash::Sha1); hash.addData(&file); const QByteArray checksum = hash.result().toHex(); - const QByteArray expectedChecksum = hashFile.readAll(); - if (checksum != expectedChecksum) { + if (!QFileInfo::exists(dir.absolutePath() + QDir::separator() + + QString::fromLatin1(checksum) + QLatin1String(".sha1"))) { qCWarning(QInstaller::lcInstallerInstallLog) << "Unexpected checksum for file" << file.fileName(); return false; diff --git a/src/libs/installer/metadatajob_p.h b/src/libs/installer/metadatajob_p.h index 0bd47b324..837a7e9ae 100644 --- a/src/libs/installer/metadatajob_p.h +++ b/src/libs/installer/metadatajob_p.h @@ -115,14 +115,14 @@ public: hash.addData(&file); const QByteArray hexChecksum = hash.result().toHex(); - QFile hashFile(file.fileName() + QLatin1String(".sha1")); + QFileInfo fileInfo(file.fileName()); + QFile hashFile(fileInfo.absolutePath() + QDir::separator() + + QString::fromLatin1(hexChecksum) + QLatin1String(".sha1")); if (!hashFile.open(QIODevice::WriteOnly)) { fi.reportException(UnzipArchiveException(MetadataJob::tr("Cannot open file \"%1\" for " "writing: %2").arg(QDir::toNativeSeparators(hashFile.fileName()), hashFile.errorString()))); break; } - QTextStream stream(&hashFile); - stream << hexChecksum; } } |