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