From 3fbf3fee209587b03bdfe21d5bcccf800c78d97b Mon Sep 17 00:00:00 2001 From: Arttu Tarkiainen Date: Wed, 22 Feb 2023 14:24:05 +0200 Subject: Metadata cache: add warning for Updates.xml checksum mismatches The vendor may provide information about expected checksum for a repository Updates.xml file, so that installer does not download it again if it is found in cache. If the expected checksum does not match the checksum of the actually downloaded file, installer will try to download it again and again for each metadata fetch. Detect such mismatch and print a warning to catch those more easily. Change-Id: I81d2e6e7c4f448229c35ab54c03bcfc3584f304d Reviewed-by: Katja Marttila --- src/libs/installer/metadatajob.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/libs/installer/metadatajob.cpp b/src/libs/installer/metadatajob.cpp index b5883c66c..f90bfad9b 100644 --- a/src/libs/installer/metadatajob.cpp +++ b/src/libs/installer/metadatajob.cpp @@ -766,13 +766,21 @@ MetadataJob::Status MetadataJob::parseUpdatesXml(const QList &re return XmlDownloadFailure; } const FileTaskItem item = result.value(TaskRole::TaskItem).value(); + const Repository repository = item.value(TaskRole::UserRole).value(); - // Check if we have cached the metadata for this repository already QCryptographicHash hash(QCryptographicHash::Sha1); hash.addData(&file); const QByteArray updatesChecksum = hash.result().toHex(); + if (!repository.xmlChecksum().isEmpty() && updatesChecksum != repository.xmlChecksum()) { + qCWarning(lcDeveloperBuild).noquote().nospace() << "The checksum for Updates.xml " + "file downloaded from repository:\n" << repository.url().toString() << "\ndoes not " + "match the expected value:\n\tActual SHA1: " << updatesChecksum << "\n\tExpected SHA1: " + << repository.xmlChecksum() << Qt::endl; + } + bool refreshed; + // Check if we have cached the metadata for this repository already Status status = refreshCacheItem(result, updatesChecksum, &refreshed); if (status != XmlDownloadSuccess) return status; @@ -794,7 +802,7 @@ MetadataJob::Status MetadataJob::parseUpdatesXml(const QList &re } file.close(); - metadata->setRepository(item.value(TaskRole::UserRole).value()); + metadata->setRepository(repository); const bool online = !(metadata->repository().url().scheme()).isEmpty(); bool testCheckSum = true; @@ -881,6 +889,7 @@ MetadataJob::Status MetadataJob::refreshCacheItem(const FileTaskResult &result, const FileTaskItem item = result.value(TaskRole::TaskItem).value(); const Repository repository = item.value(TaskRole::UserRole).value(); + if (cachedMetadata->isValid() && !repository.isCompressed()) { // Refresh repository information to cache. Same repository may appear in multiple // categories and the metadata may be available from default repositories simultaneously. -- cgit v1.2.3