Blame SOURCES/0014-Add-api-function-fill-sack-from-repos-in-cache-RhBug-1865803.patch

31f77b
From b3542a96c6f77e5cc0b5217e586fcc56fde074d8 Mon Sep 17 00:00:00 2001
31f77b
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
31f77b
Date: Wed, 2 Dec 2020 15:27:13 +0100
31f77b
Subject: [PATCH 1/2] Add api function: fill_sack_from_repos_in_cache
31f77b
 (RhBug:1865803)
31f77b
31f77b
= changelog =
31f77b
msg: Add api function fill_sack_from_repos_in_cache to allow loading a repo cache with repomd and (solv file or primary xml) only
31f77b
type: enhancement
31f77b
resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1865803
31f77b
---
31f77b
 dnf.spec    |  2 +-
31f77b
 dnf/base.py | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++
31f77b
 2 files changed, 63 insertions(+), 1 deletion(-)
31f77b
31f77b
diff --git a/dnf/base.py b/dnf/base.py
31f77b
index 075e74265a..a10b837340 100644
31f77b
--- a/dnf/base.py
31f77b
+++ b/dnf/base.py
31f77b
@@ -425,6 +425,68 @@ def fill_sack(self, load_system_repo=True, load_available_repos=True):
31f77b
         self._plugins.run_sack()
31f77b
         return self._sack
31f77b
 
31f77b
+    def fill_sack_from_repos_in_cache(self, load_system_repo=True):
31f77b
+        # :api
31f77b
+        """
31f77b
+        Prepare Sack and Goal objects and also load all enabled repositories from cache only,
31f77b
+        it doesn't download anything and it doesn't check if metadata are expired.
31f77b
+        If there is not enough metadata present (repond.xml or both primary.xml and solv file
31f77b
+        are missing) given repo is either skipped or it throws a RepoError exception depending
31f77b
+        on skip_if_unavailable configuration.
31f77b
+        """
31f77b
+        timer = dnf.logging.Timer('sack setup')
31f77b
+        self.reset(sack=True, goal=True)
31f77b
+        self._sack = dnf.sack._build_sack(self)
31f77b
+        lock = dnf.lock.build_metadata_lock(self.conf.cachedir, self.conf.exit_on_lock)
31f77b
+        with lock:
31f77b
+            if load_system_repo is not False:
31f77b
+                try:
31f77b
+                    # FIXME: If build_cache=True, @System.solv is incorrectly updated in install-
31f77b
+                    # remove loops
31f77b
+                    self._sack.load_system_repo(build_cache=False)
31f77b
+                except IOError:
31f77b
+                    if load_system_repo != 'auto':
31f77b
+                        raise
31f77b
+
31f77b
+            error_repos = []
31f77b
+            # Iterate over installed GPG keys and check their validity using DNSSEC
31f77b
+            if self.conf.gpgkey_dns_verification:
31f77b
+                dnf.dnssec.RpmImportedKeys.check_imported_keys_validity()
31f77b
+            for repo in self.repos.iter_enabled():
31f77b
+                try:
31f77b
+                    repo._repo.loadCache(throwExcept=True, ignoreMissing=True)
31f77b
+                    mdload_flags = dict(load_filelists=True,
31f77b
+                                        load_presto=repo.deltarpm,
31f77b
+                                        load_updateinfo=True)
31f77b
+                    if repo.load_metadata_other:
31f77b
+                        mdload_flags["load_other"] = True
31f77b
+
31f77b
+                    self._sack.load_repo(repo._repo, **mdload_flags)
31f77b
+
31f77b
+                    logger.debug(_("%s: using metadata from %s."), repo.id,
31f77b
+                                 dnf.util.normalize_time(
31f77b
+                                     repo._repo.getMaxTimestamp()))
31f77b
+                except (RuntimeError, hawkey.Exception) as e:
31f77b
+                    if repo.skip_if_unavailable is False:
31f77b
+                        raise dnf.exceptions.RepoError(
31f77b
+                            _("loading repo '{}' failure: {}").format(repo.id, e))
31f77b
+                    else:
31f77b
+                        logger.debug(_("loading repo '{}' failure: {}").format(repo.id, e))
31f77b
+                    error_repos.append(repo.id)
31f77b
+                    repo.disable()
31f77b
+            if error_repos:
31f77b
+                logger.warning(
31f77b
+                    _("Ignoring repositories: %s"), ', '.join(error_repos))
31f77b
+
31f77b
+        conf = self.conf
31f77b
+        self._sack._configure(conf.installonlypkgs, conf.installonly_limit, conf.allow_vendor_change)
31f77b
+        self._setup_excludes_includes()
31f77b
+        timer()
31f77b
+        self._goal = dnf.goal.Goal(self._sack)
31f77b
+        self._goal.protect_running_kernel = conf.protect_running_kernel
31f77b
+        self._plugins.run_sack()
31f77b
+        return self._sack
31f77b
+
31f77b
     def _finalize_base(self):
31f77b
         self._tempfile_persistor = dnf.persistor.TempfilePersistor(
31f77b
             self.conf.cachedir)
31f77b
31f77b
From 29ae53918d4a0b65a917aca2f8f43416fee15dfd Mon Sep 17 00:00:00 2001
31f77b
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
31f77b
Date: Thu, 10 Dec 2020 14:54:16 +0100
31f77b
Subject: [PATCH 2/2] Add api test for new fill_sack_from_repos_in_cache
31f77b
31f77b
---
31f77b
 tests/api/test_dnf_base.py | 6 ++++++
31f77b
 1 file changed, 6 insertions(+)
31f77b
31f77b
diff --git a/tests/api/test_dnf_base.py b/tests/api/test_dnf_base.py
31f77b
index 656bd22584..335981897e 100644
31f77b
--- a/tests/api/test_dnf_base.py
31f77b
+++ b/tests/api/test_dnf_base.py
31f77b
@@ -107,6 +107,12 @@ def test_fill_sack(self):
31f77b
 
31f77b
         self.base.fill_sack(load_system_repo=False, load_available_repos=False)
31f77b
 
31f77b
+    def test_fill_sack_from_repos_in_cache(self):
31f77b
+        # Base.fill_sack_from_repos_in_cache(self, load_system_repo=True):
31f77b
+        self.assertHasAttr(self.base, "fill_sack_from_repos_in_cache")
31f77b
+
31f77b
+        self.base.fill_sack_from_repos_in_cache(load_system_repo=False)
31f77b
+
31f77b
     def test_close(self):
31f77b
         # Base.close()
31f77b
         self.assertHasAttr(self.base, "close")