From e5a00edb02bcbf9f9b25b33a91f5544a4801dabc Mon Sep 17 00:00:00 2001 From: Troy Dawson Date: Fri, 25 Mar 2022 10:14:33 -0700 Subject: [PATCH] Add patch for providerFileUrl and caching (#2068568) --- kf5-knewstuff.spec | 9 +++- knewstuff-5.88.0-providersurl-cache.patch | 58 +++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 knewstuff-5.88.0-providersurl-cache.patch diff --git a/kf5-knewstuff.spec b/kf5-knewstuff.spec index 65ce4a9..e4b27b6 100644 --- a/kf5-knewstuff.spec +++ b/kf5-knewstuff.spec @@ -3,7 +3,7 @@ Name: kf5-%{framework} Version: 5.90.0 -Release: 1%{?dist} +Release: 2%{?dist} Summary: KDE Frameworks 5 Tier 3 module for downloading application assets License: LGPLv2+ @@ -20,6 +20,10 @@ Source0: http://download.kde.org/%{stable}/frameworks/%{majmin}/%{framework}-%{v ## upstream patches +## Backported patches +# https://bugzilla.redhat.com/show_bug.cgi?id=2065761 +Patch300: knewstuff-5.88.0-providersurl-cache.patch + # filter qml provides %global __provides_exclude_from ^%{_kf5_qmldir}/.*\\.so$ @@ -106,6 +110,9 @@ developing applications that use %{name}. %changelog +* Fri Mar 25 2022 Troy Dawson - 5.90.0-2 +- Add patch for providerFileUrl and caching (#2068568) + * Tue Jan 04 2022 Marc Deop i Argemí (Private) - 5.90.0-1 - 5.90.0 diff --git a/knewstuff-5.88.0-providersurl-cache.patch b/knewstuff-5.88.0-providersurl-cache.patch new file mode 100644 index 0000000..15f324e --- /dev/null +++ b/knewstuff-5.88.0-providersurl-cache.patch @@ -0,0 +1,58 @@ +From 4e7a1a65d0872bc905bd1355670397f4993b86b1 Mon Sep 17 00:00:00 2001 +From: Troy Dawson +Date: Fri, 18 Mar 2022 10:54:00 -0700 +Subject: [PATCH] providersurl-cache + +--- + src/core/engine.cpp | 4 ++++ + src/core/jobs/httpworker.cpp | 12 +++++++++++- + 2 files changed, 15 insertions(+), 1 deletion(-) + +diff --git a/src/core/engine.cpp b/src/core/engine.cpp +index 428af1b..9c2990c 100644 +--- a/src/core/engine.cpp ++++ b/src/core/engine.cpp +@@ -265,6 +265,10 @@ bool Engine::init(const QString &configfile) + Q_EMIT uploadEnabledChanged(); + + m_providerFileUrl = group.readEntry("ProvidersUrl"); ++ if (m_providerFileUrl == QLatin1String("https://download.kde.org/ocs/providers.xml")) { ++ m_providerFileUrl = QStringLiteral("https://autoconfig.kde.org/ocs/providers.xml"); ++ qCWarning(KNEWSTUFFCORE) << "Please make sure" << configfile << "has ProvidersUrl=https://autoconfig.kde.org/ocs/providers.xml"; ++ } + if (group.readEntry("UseLocalProvidersFile", "false").toLower() == QLatin1String{"true"}) { + // The local providers file is called "appname.providers", to match "appname.knsrc" + m_providerFileUrl = QUrl::fromLocalFile(QLatin1String("%1.providers").arg(configFullPath.left(configFullPath.length() - 6))).toString(); +diff --git a/src/core/jobs/httpworker.cpp b/src/core/jobs/httpworker.cpp +index b81edd2..d4dd8a2 100644 +--- a/src/core/jobs/httpworker.cpp ++++ b/src/core/jobs/httpworker.cpp +@@ -41,7 +41,6 @@ public: + return nam.get(request); + } + +-private: + QNetworkDiskCache cache; + }; + +@@ -102,6 +101,17 @@ static void addUserAgent(QNetworkRequest &request) + agentHeader += QStringLiteral("-%1/%2").arg(QCoreApplication::instance()->applicationName(), QCoreApplication::instance()->applicationVersion()); + } + request.setHeader(QNetworkRequest::UserAgentHeader, agentHeader); ++ ++ // Assume that no cache expiration time will be longer than a week, but otherwise prefer the cache ++ // This is mildly hacky, but if we don't do this, we end up with infinite cache expirations in some ++ // cases, which of course isn't really acceptable... See ed62ee20 for a situation where that happened. ++ QNetworkCacheMetaData cacheMeta{s_httpWorkerNAM->cache.metaData(request.url())}; ++ if (cacheMeta.isValid()) { ++ const QDateTime nextWeek{QDateTime::currentDateTime().addDays(7)}; ++ if (cacheMeta.expirationDate().isValid() && cacheMeta.expirationDate() < nextWeek) { ++ request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); ++ } ++ } + } + + void HTTPWorker::startRequest() +-- +2.27.0 +