summaryrefslogtreecommitdiffstats
path: root/src/libs/installer
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/installer')
-rw-r--r--src/libs/installer/metadata.cpp29
-rw-r--r--src/libs/installer/metadata.h2
-rw-r--r--src/libs/installer/metadatajob.cpp16
3 files changed, 40 insertions, 7 deletions
diff --git a/src/libs/installer/metadata.cpp b/src/libs/installer/metadata.cpp
index 0469ed8b1..c9fa0a0f1 100644
--- a/src/libs/installer/metadata.cpp
+++ b/src/libs/installer/metadata.cpp
@@ -36,6 +36,7 @@
#include <QDir>
#include <QDomDocument>
#include <QFile>
+#include <QByteArrayMatcher>
namespace QInstaller {
@@ -254,4 +255,32 @@ QString Metadata::persistentRepositoryPath()
return m_persistentRepositoryPath;
}
+/*!
+ Checks whether the updates document of this metadata contains the repository
+ update element, which can include actions to \c add, \c remove, and \c replace
+ repositories.
+
+ \note This function does not check that the repository updates are actually
+ valid, only that the updates document contains the \c RepositoryUpdate element.
+*/
+bool Metadata::containsRepositoryUpdates() const
+{
+ QFile updateFile(path() + QLatin1String("/Updates.xml"));
+ if (!updateFile.open(QIODevice::ReadOnly)) {
+ qCWarning(QInstaller::lcInstallerInstallLog)
+ << "Cannot open" << updateFile.fileName()
+ << "for reading:" << updateFile.errorString();
+ return false;
+ }
+
+ static const auto matcher = qMakeStaticByteArrayMatcher("<RepositoryUpdate>");
+ while (!updateFile.atEnd()) {
+ const QByteArray line = updateFile.readLine().simplified();
+ if (matcher.indexIn(line) != -1)
+ return true;
+ }
+
+ return false;
+}
+
} // namespace QInstaller
diff --git a/src/libs/installer/metadata.h b/src/libs/installer/metadata.h
index af7acf6b9..3063be829 100644
--- a/src/libs/installer/metadata.h
+++ b/src/libs/installer/metadata.h
@@ -61,6 +61,8 @@ public:
void setPersistentRepositoryPath(const QUrl &url);
QString persistentRepositoryPath();
+ bool containsRepositoryUpdates() const;
+
private:
Repository m_repository;
QString m_persistentRepositoryPath;
diff --git a/src/libs/installer/metadatajob.cpp b/src/libs/installer/metadatajob.cpp
index 5a7aa66f4..33aabd268 100644
--- a/src/libs/installer/metadatajob.cpp
+++ b/src/libs/installer/metadatajob.cpp
@@ -862,13 +862,15 @@ MetadataJob::Status MetadataJob::refreshCacheItem(const FileTaskResult &result,
cachedMetadata->setPersistentRepositoryPath(repository.url());
// search for additional repositories that we might need to check
- QDomDocument doc = cachedMetadata->updatesDocument();
- const Status status = parseRepositoryUpdates(doc.documentElement(), result, cachedMetadata);
- if (status == XmlDownloadRetry) {
- // The repository update may have removed or replaced current repositories,
- // clear repository information from cached items and refresh on next fetch run.
- resetCacheRepositories();
- return status;
+ if (cachedMetadata->containsRepositoryUpdates()) {
+ QDomDocument doc = cachedMetadata->updatesDocument();
+ const Status status = parseRepositoryUpdates(doc.documentElement(), result, cachedMetadata);
+ if (status == XmlDownloadRetry) {
+ // The repository update may have removed or replaced current repositories,
+ // clear repository information from cached items and refresh on next fetch run.
+ resetCacheRepositories();
+ return status;
+ }
}
*refreshed = true;
return XmlDownloadSuccess;