richardphibel / rpms / libdnf

Forked from rpms/libdnf 2 years ago
Clone
925316
From e83ff88f8e4604024e4d5f4fd9f2fa4e5d4f03f9 Mon Sep 17 00:00:00 2001
925316
From: Jaroslav Mracek <jmracek@redhat.com>
925316
Date: Tue, 23 Nov 2021 14:14:23 +0100
925316
Subject: [PATCH] Add getLatestModules()
925316
925316
It returns latest module packages for each module name, stream, and
925316
architecture.
925316
925316
It is an alternative implementation to code base with
925316
the old modular solver.
925316
925316
Alternative to 73868368120ceea97ada628a1aa42236fb42b89d
925316
---
925316
 libdnf/module/ModulePackageContainer.cpp | 39 +++++++++++++++++++++++++++++++++++++++
925316
 libdnf/module/ModulePackageContainer.hpp |  9 +++++++++
925316
 2 files changed, 48 insertions(+)
925316
925316
diff --git a/libdnf/module/ModulePackageContainer.cpp b/libdnf/module/ModulePackageContainer.cpp
925316
index efab497..f9f861c 100644
925316
--- a/libdnf/module/ModulePackageContainer.cpp
925316
+++ b/libdnf/module/ModulePackageContainer.cpp
925316
@@ -1037,6 +1037,45 @@ ModulePackageContainer::getLatestModulesPerRepo(ModuleState moduleFilter,
925316
     return output;
925316
 }
925316
 
925316
+std::vector<ModulePackage *>
925316
+ModulePackageContainer::getLatestModules(const std::vector<ModulePackage *> modulePackages, bool activeOnly)
925316
+{
925316
+    std::vector<ModulePackage *> latestModules;
925316
+    if (activeOnly) {
925316
+        // When no active module return
925316
+        if (!pImpl->activatedModules) {
925316
+            return latestModules;
925316
+        }
925316
+    }
925316
+    std::map<std::string, std::vector<ModulePackage *>> latest;
925316
+
925316
+    for (auto modulePackage : modulePackages) {
925316
+        if (activeOnly && !isModuleActive(modulePackage)) {
925316
+            continue;
925316
+        }
925316
+        auto nameStreamArch = modulePackage->getNameStream();
925316
+        nameStreamArch.append(":");
925316
+        nameStreamArch.append(modulePackage->getArchCStr());
925316
+        auto & entries = latest[nameStreamArch];
925316
+        if (entries.empty()) {
925316
+            entries.push_back(modulePackage);
925316
+        } else {
925316
+            auto version = (*entries.begin())->getVersionNum();
925316
+            if (version < modulePackage->getVersionNum()) {
925316
+                entries.clear();
925316
+                entries.push_back(modulePackage);
925316
+            } else if (version == modulePackage->getVersionNum()) {
925316
+                entries.push_back(modulePackage);
925316
+            }
925316
+        }
925316
+    }
925316
+    for (auto & entries : latest) {
925316
+        for (auto modulePackage : entries.second) {
925316
+            latestModules.push_back(modulePackage);
925316
+        }
925316
+    }
925316
+    return latestModules;
925316
+}
925316
 
925316
 std::pair<std::vector<std::vector<std::string>>, ModulePackageContainer::ModuleErrorType>
925316
 ModulePackageContainer::resolveActiveModulePackages(bool debugSolver)
925316
diff --git a/libdnf/module/ModulePackageContainer.hpp b/libdnf/module/ModulePackageContainer.hpp
925316
index 7e5071b..42d5a9e 100644
925316
--- a/libdnf/module/ModulePackageContainer.hpp
925316
+++ b/libdnf/module/ModulePackageContainer.hpp
925316
@@ -132,6 +132,15 @@ public:
925316
     std::vector<std::vector<std::vector<ModulePackage *>>> getLatestModulesPerRepo(
925316
         ModuleState moduleFilter, std::vector<ModulePackage *> modulePackages);
925316
 
925316
+    /**
925316
+    * @brief Return all latest ModulePackages for each module Name, stream and architecture. In case of
925316
+    * multiple latest packages, all will be returned. When activeOnly is true, it returns only the latest active
925316
+    * packages.
925316
+    *
925316
+    * @return std::vector<ModulePackage *>
925316
+    */
925316
+    std::vector<ModulePackage *> getLatestModules(const std::vector<ModulePackage *> modulePackages, bool activeOnly);
925316
+
925316
     std::vector<ModulePackage *> requiresModuleEnablement(const libdnf::PackageSet & packages);
925316
 
925316
     /**
925316
--
925316
libgit2 1.1.0
925316