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

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