chantra / rpms / libdnf

Forked from rpms/libdnf 2 years ago
Clone

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

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