Blame SOURCES/0005-reposync-Add-latest-NEVRAs-per-stream-to-download-RhBug-1833074.patch

c82c2f
From dc71c83ba6a47fb86d7dc5a750df0f262cec3d1b Mon Sep 17 00:00:00 2001
c82c2f
From: Marek Blaha <mblaha@redhat.com>
c82c2f
Date: Thu, 23 Jul 2020 16:27:22 +0200
c82c2f
Subject: [PATCH] [reposync] Add latest NEVRAs per stream to download (RhBug: 1833074)
c82c2f
c82c2f
This covers situation when package with the newest NEVRA is part of
c82c2f
an older version of a stream and reposync was used with --newest-only
c82c2f
switch.
c82c2f
With this patch these package versions are going to be downloaded:
c82c2f
- the latest NEVRAs from non-modular packages
c82c2f
- all packages from stream version with the latest package NEVRA (in
c82c2f
  case the latest NEVRA is part of multiple stream versions only the
c82c2f
  highest is downloaded)
c82c2f
- all packages from the latest stream version
c82c2f
c82c2f
https://bugzilla.redhat.com/show_bug.cgi?id=1833074
c82c2f
---
c82c2f
 plugins/reposync.py | 53 +++++++++++++++++++++++++++++++++++++++++++----------
c82c2f
 1 file changed, 43 insertions(+), 10 deletions(-)
c82c2f
c82c2f
diff --git a/plugins/reposync.py b/plugins/reposync.py
c82c2f
index 8306651..67827f4 100644
c82c2f
--- a/plugins/reposync.py
c82c2f
+++ b/plugins/reposync.py
c82c2f
@@ -200,27 +200,60 @@ class RepoSyncCommand(dnf.cli.Command):
c82c2f
 
c82c2f
     def _get_latest(self, query):
c82c2f
         """
c82c2f
-        return query with latest nonmodular package and all packages from latest version per stream
c82c2f
+        return union of these queries:
c82c2f
+        - the latest NEVRAs from non-modular packages
c82c2f
+        - all packages from stream version with the latest package NEVRA
c82c2f
+          (this should not be needed but the latest package NEVRAs might be
c82c2f
+          part of an older module version)
c82c2f
+        - all packages from the latest stream version
c82c2f
         """
c82c2f
         if not dnf.base.WITH_MODULES:
c82c2f
             return query.latest()
c82c2f
+
c82c2f
         query.apply()
c82c2f
         module_packages = self.base._moduleContainer.getModulePackages()
c82c2f
         all_artifacts = set()
c82c2f
         module_dict = {}  # {NameStream: {Version: [modules]}}
c82c2f
+        artifact_version = {} # {artifact: {NameStream: [Version]}}
c82c2f
         for module_package in module_packages:
c82c2f
-            all_artifacts.update(module_package.getArtifacts())
c82c2f
+            artifacts = module_package.getArtifacts()
c82c2f
+            all_artifacts.update(artifacts)
c82c2f
             module_dict.setdefault(module_package.getNameStream(), {}).setdefault(
c82c2f
                 module_package.getVersionNum(), []).append(module_package)
c82c2f
-        non_modular_latest = query.filter(
c82c2f
+            for artifact in artifacts:
c82c2f
+                artifact_version.setdefault(artifact, {}).setdefault(
c82c2f
+                    module_package.getNameStream(), []).append(module_package.getVersionNum())
c82c2f
+
c82c2f
+        # the latest NEVRAs from non-modular packages
c82c2f
+        latest_query = query.filter(
c82c2f
             pkg__neq=query.filter(nevra_strict=all_artifacts)).latest()
c82c2f
-        latest_artifacts = set()
c82c2f
-        for version_dict in module_dict.values():
c82c2f
-            keys = sorted(version_dict.keys(), reverse=True)
c82c2f
-            for module in version_dict[keys[0]]:
c82c2f
-                latest_artifacts.update(module.getArtifacts())
c82c2f
-        latest_modular_query = query.filter(nevra_strict=latest_artifacts)
c82c2f
-        return latest_modular_query.union(non_modular_latest)
c82c2f
+
c82c2f
+        # artifacts from the newest version and those versions that contain an artifact
c82c2f
+        # with the highest NEVRA
c82c2f
+        latest_stream_artifacts = set()
c82c2f
+        for namestream, version_dict in module_dict.items():
c82c2f
+            # versions that will be synchronized
c82c2f
+            versions = set()
c82c2f
+            # add the newest stream version
c82c2f
+            versions.add(sorted(version_dict.keys(), reverse=True)[0])
c82c2f
+            # collect all artifacts in all stream versions
c82c2f
+            stream_artifacts = set()
c82c2f
+            for modules in version_dict.values():
c82c2f
+                for module in modules:
c82c2f
+                    stream_artifacts.update(module.getArtifacts())
c82c2f
+            # find versions to which the packages with the highest NEVRAs belong
c82c2f
+            for latest_pkg in query.filter(nevra_strict=stream_artifacts).latest():
c82c2f
+                # here we depend on modules.yaml allways containing full NEVRA (including epoch)
c82c2f
+                nevra = "{0.name}-{0.epoch}:{0.version}-{0.release}.{0.arch}".format(latest_pkg)
c82c2f
+                # download only highest version containing the latest artifact
c82c2f
+                versions.add(max(artifact_version[nevra][namestream]))
c82c2f
+            # add all artifacts from selected versions for synchronization
c82c2f
+            for version in versions:
c82c2f
+                for module in version_dict[version]:
c82c2f
+                    latest_stream_artifacts.update(module.getArtifacts())
c82c2f
+        latest_query = latest_query.union(query.filter(nevra_strict=latest_stream_artifacts))
c82c2f
+
c82c2f
+        return latest_query
c82c2f
 
c82c2f
     def get_pkglist(self, repo):
c82c2f
         query = self.base.sack.query(flags=hawkey.IGNORE_MODULAR_EXCLUDES).available().filterm(
c82c2f
--
c82c2f
libgit2 0.28.5
c82c2f