Blame SOURCES/0002-Redesign-reposync-latest-for-modular-system-RhBug1775434.patch

22d84c
From b60770dba985dfaab8bedc04e7c3b6a5c3a59d51 Mon Sep 17 00:00:00 2001
22d84c
From: Jaroslav Mracek <jmracek@redhat.com>
22d84c
Date: Fri, 29 Nov 2019 10:48:55 +0100
22d84c
Subject: [PATCH] Redesign reposync --newest_only for modular system
22d84c
 (RhBug:1775434)
22d84c
22d84c
reposync --newest_only will download all latest non-modular packages
22d84c
plus all packages for contexts with latest version for each module
22d84c
stream.
22d84c
22d84c
https://bugzilla.redhat.com/show_bug.cgi?id=1775434
22d84c
---
22d84c
 plugins/reposync.py | 26 +++++++++++++++++++++++++-
22d84c
 1 file changed, 25 insertions(+), 1 deletion(-)
22d84c
22d84c
diff --git a/plugins/reposync.py b/plugins/reposync.py
22d84c
index 10e9b0b5..c1bc6a99 100644
22d84c
--- a/plugins/reposync.py
22d84c
+++ b/plugins/reposync.py
22d84c
@@ -203,11 +203,35 @@ def download_metadata(self, repo):
22d84c
         repo._repo.downloadMetadata(repo_target)
22d84c
         return True
22d84c
 
22d84c
+    def _get_latest(self, query):
22d84c
+        """
22d84c
+        return query with latest nonmodular package and all packages from latest version per stream
22d84c
+        """
22d84c
+        if not dnf.base.WITH_MODULES:
22d84c
+            return query.latest()
22d84c
+        query.apply()
22d84c
+        module_packages = self.base._moduleContainer.getModulePackages()
22d84c
+        all_artifacts = set()
22d84c
+        module_dict = {}  # {NameStream: {Version: [modules]}}
22d84c
+        for module_package in module_packages:
22d84c
+            all_artifacts.update(module_package.getArtifacts())
22d84c
+            module_dict.setdefault(module_package.getNameStream(), {}).setdefault(
22d84c
+                module_package.getVersionNum(), []).append(module_package)
22d84c
+        non_modular_latest = query.filter(
22d84c
+            pkg__neq=query.filter(nevra_strict=all_artifacts)).latest()
22d84c
+        latest_artifacts = set()
22d84c
+        for version_dict in module_dict.values():
22d84c
+            keys = sorted(version_dict.keys(), reverse=True)
22d84c
+            for module in version_dict[keys[0]]:
22d84c
+                latest_artifacts.update(module.getArtifacts())
22d84c
+        latest_modular_query = query.filter(nevra_strict=latest_artifacts)
22d84c
+        return latest_modular_query.union(non_modular_latest)
22d84c
+
22d84c
     def get_pkglist(self, repo):
22d84c
         query = self.base.sack.query(flags=hawkey.IGNORE_MODULAR_EXCLUDES).available().filterm(
22d84c
             reponame=repo.id)
22d84c
         if self.opts.newest_only:
22d84c
-            query = query.latest()
22d84c
+            query = self._get_latest(query)
22d84c
         if self.opts.source:
22d84c
             query.filterm(arch='src')
22d84c
         elif self.opts.arches: