Blame SOURCES/0005-Allow-loading-incomplete-cache-and-loading-ext-solv-files-without-its-repodata.patch

504788
From 816d18d826dc7134e553eae28f4aaca9a27e2307 Mon Sep 17 00:00:00 2001
504788
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
504788
Date: Mon, 2 Nov 2020 11:43:19 +0100
504788
Subject: [PATCH 1/2] Allow loading ext metadata even if only cache (solv) is
504788
 present
504788
504788
If we have a valid (checksum matches with repomd) solv file for
504788
requested type of metadata allow using it even if we no longer have the
504788
original xml metadata.
504788
---
504788
 libdnf/dnf-sack.cpp | 22 +++++++++++-----------
504788
 1 file changed, 11 insertions(+), 11 deletions(-)
504788
504788
diff --git a/libdnf/dnf-sack.cpp b/libdnf/dnf-sack.cpp
504788
index 6a43f01e3..608103d18 100644
504788
--- a/libdnf/dnf-sack.cpp
504788
+++ b/libdnf/dnf-sack.cpp
504788
@@ -371,20 +371,9 @@ load_ext(DnfSack *sack, HyRepo hrepo, _hy_repo_repodata which_repodata,
504788
     auto repoImpl = libdnf::repoGetImpl(hrepo);
504788
     Repo *repo = repoImpl->libsolvRepo;
504788
     const char *name = repo->name;
504788
-    auto fn = hrepo->getMetadataPath(which_filename);
504788
     FILE *fp;
504788
     gboolean done = FALSE;
504788
 
504788
-    /* nothing set */
504788
-    if (fn.empty()) {
504788
-        g_set_error (error,
504788
-                     DNF_ERROR,
504788
-                     DNF_ERROR_NO_CAPABILITY,
504788
-                     _("no %1$s string for %2$s"),
504788
-                     which_filename, name);
504788
-        return FALSE;
504788
-    }
504788
-
504788
     char *fn_cache =  dnf_sack_give_cache_fn(sack, name, suffix);
504788
     fp = fopen(fn_cache, "r");
504788
     assert(libdnf::repoGetImpl(hrepo)->checksum);
504788
@@ -416,6 +405,17 @@ load_ext(DnfSack *sack, HyRepo hrepo, _hy_repo_repodata which_repodata,
504788
     if (done)
504788
         return TRUE;
504788
 
504788
+    auto fn = hrepo->getMetadataPath(which_filename);
504788
+    /* nothing set */
504788
+    if (fn.empty()) {
504788
+        g_set_error (error,
504788
+                     DNF_ERROR,
504788
+                     DNF_ERROR_NO_CAPABILITY,
504788
+                     _("no %1$s string for %2$s"),
504788
+                     which_filename, name);
504788
+        return FALSE;
504788
+    }
504788
+
504788
     fp = solv_xfopen(fn.c_str(), "r");
504788
     if (fp == NULL) {
504788
         g_set_error (error,
504788
504788
From aa2a372158f1b264708f960f387218deea17ef2a Mon Sep 17 00:00:00 2001
504788
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
504788
Date: Thu, 10 Dec 2020 14:21:03 +0100
504788
Subject: [PATCH 2/2] Extend repo loadCache method with ignoreMissing parameter
504788
504788
This allows loading even incomplete cache of xml files, only repomd.xml
504788
is requried.
504788
504788
= changelog =
504788
msg: Extend repo loadCache method with ignoreMissing parameter to allow
504788
loading incomplete xml cache (repomd.xml is required).
504788
type: enhancement
504788
resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1865803
504788
---
504788
 VERSION.cmake                | 2 +-
504788
 libdnf.spec                  | 2 +-
504788
 libdnf/repo/Repo-private.hpp | 2 +-
504788
 libdnf/repo/Repo.cpp         | 8 ++++++--
504788
 libdnf/repo/Repo.hpp         | 2 +-
504788
 5 files changed, 10 insertions(+), 6 deletions(-)
504788
504788
diff --git a/libdnf/repo/Repo-private.hpp b/libdnf/repo/Repo-private.hpp
504788
index 1e4ea4d20..c2ce369dc 100644
504788
--- a/libdnf/repo/Repo-private.hpp
504788
+++ b/libdnf/repo/Repo-private.hpp
504788
@@ -111,7 +111,7 @@ class Repo::Impl {
504788
     ~Impl();
504788
 
504788
     bool load();
504788
-    bool loadCache(bool throwExcept);
504788
+    bool loadCache(bool throwExcept, bool ignoreMissing=false);
504788
     void downloadMetadata(const std::string & destdir);
504788
     bool isInSync();
504788
     void fetch(const std::string & destdir, std::unique_ptr<LrHandle> && h);
504788
diff --git a/libdnf/repo/Repo.cpp b/libdnf/repo/Repo.cpp
504788
index 34539e1ee..84702c294 100644
504788
--- a/libdnf/repo/Repo.cpp
504788
+++ b/libdnf/repo/Repo.cpp
504788
@@ -379,7 +379,7 @@ std::string Repo::getLocalBaseurl() const
504788
 }
504788
 
504788
 bool Repo::load() { return pImpl->load(); }
504788
-bool Repo::loadCache(bool throwExcept) { return pImpl->loadCache(throwExcept); }
504788
+bool Repo::loadCache(bool throwExcept, bool ignoreMissing) { return pImpl->loadCache(throwExcept, ignoreMissing); }
504788
 void Repo::downloadMetadata(const std::string & destdir) { pImpl->downloadMetadata(destdir); }
504788
 bool Repo::getUseIncludes() const { return pImpl->useIncludes; }
504788
 void Repo::setUseIncludes(bool enabled) { pImpl->useIncludes = enabled; }
504788
@@ -963,11 +963,15 @@ std::unique_ptr<LrResult> Repo::Impl::lrHandlePerform(LrHandle * handle, const s
504788
     return result;
504788
 }
504788
 
504788
-bool Repo::Impl::loadCache(bool throwExcept)
504788
+bool Repo::Impl::loadCache(bool throwExcept, bool ignoreMissing)
504788
 {
504788
     std::unique_ptr<LrHandle> h(lrHandleInitLocal());
504788
     std::unique_ptr<LrResult> r;
504788
 
504788
+    if (ignoreMissing) {
504788
+        handleSetOpt(h.get(), LRO_IGNOREMISSING, 1L);
504788
+    }
504788
+
504788
     // Fetch data
504788
     try {
504788
         r = lrHandlePerform(h.get(), getCachedir(), conf->repo_gpgcheck().getValue());
504788
diff --git a/libdnf/repo/Repo.hpp b/libdnf/repo/Repo.hpp
504788
index eeec651c3..be376f60c 100644
504788
--- a/libdnf/repo/Repo.hpp
504788
+++ b/libdnf/repo/Repo.hpp
504788
@@ -167,7 +167,7 @@ struct Repo {
504788
     * @return true if fresh metadata were downloaded, false otherwise.
504788
     */
504788
     bool load();
504788
-    bool loadCache(bool throwExcept);
504788
+    bool loadCache(bool throwExcept, bool ignoreMissing=false);
504788
     void downloadMetadata(const std::string & destdir);
504788
     bool getUseIncludes() const;
504788
     void setUseIncludes(bool enabled);