Blame SOURCES/0008-Revert-Fix-load-update-FailSafe.patch

379fd8
From 140168ce29d2425ebf2b4b5b25926611a189cd84 Mon Sep 17 00:00:00 2001
379fd8
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
379fd8
Date: Sun, 25 Apr 2021 19:47:53 +0200
379fd8
Subject: [PATCH 08/19] Revert "Fix load/update FailSafe"
379fd8
379fd8
This reverts commit 244a37d772fcd5a5969085edab544fb1e7b68aad.
379fd8
---
379fd8
 libdnf/module/ModulePackageContainer.cpp | 38 ++++++++++++++++++------
379fd8
 1 file changed, 29 insertions(+), 9 deletions(-)
379fd8
379fd8
diff --git a/libdnf/module/ModulePackageContainer.cpp b/libdnf/module/ModulePackageContainer.cpp
379fd8
index e19db08b..97c84c01 100644
379fd8
--- a/libdnf/module/ModulePackageContainer.cpp
379fd8
+++ b/libdnf/module/ModulePackageContainer.cpp
379fd8
@@ -1641,7 +1641,6 @@ ModulePackageContainer::Impl::ModulePersistor::getRemovedProfiles()
379fd8
 
379fd8
 void ModulePackageContainer::loadFailSafeData()
379fd8
 {
379fd8
-    pImpl->addVersion2Modules();
379fd8
     auto persistor = pImpl->persistor->configs;
379fd8
 
379fd8
     std::map<std::string, std::pair<std::string, bool>> enabledStreams;
379fd8
@@ -1696,21 +1695,42 @@ void ModulePackageContainer::loadFailSafeData()
379fd8
 
379fd8
 std::vector<ModulePackage *> ModulePackageContainer::Impl::getLatestActiveEnabledModules()
379fd8
 {
379fd8
-    Query query(moduleSack, Query::ExcludeFlags::IGNORE_EXCLUDES);
379fd8
-    query.addFilter(HY_PKG, HY_EQ, activatedModules.get());
379fd8
-    query.addFilter(HY_PKG_REPONAME, HY_NEQ, HY_SYSTEM_REPO_NAME);
379fd8
-    query.addFilter(HY_PKG_LATEST_PER_ARCH, HY_EQ, 1);
379fd8
-    auto set = query.runSet();
379fd8
-
379fd8
     std::vector<ModulePackage *> activeModules;
379fd8
     Id moduleId = -1;
379fd8
-    while ((moduleId = set->next(moduleId)) != -1) {
379fd8
+    while ((moduleId = activatedModules->next(moduleId)) != -1) {
379fd8
         auto modulePackage = modules.at(moduleId).get();
379fd8
         if (isEnabled(modulePackage->getName(), modulePackage->getStream())) {
379fd8
             activeModules.push_back(modulePackage);
379fd8
         }
379fd8
     }
379fd8
-    return activeModules;
379fd8
+    if (activeModules.empty()) {
379fd8
+        return {};
379fd8
+    }
379fd8
+    auto sack = moduleSack;
379fd8
+    std::sort(activeModules.begin(), activeModules.end(),
379fd8
+              [sack](const ModulePackage * first, const ModulePackage * second)
379fd8
+              {return modulePackageLatestSorter(sack, first, second);});
379fd8
+
379fd8
+    auto packageFirst = activeModules[0];
379fd8
+    std::vector<ModulePackage *> latest;
379fd8
+    auto vectorSize = activeModules.size();
379fd8
+    latest.push_back(packageFirst);
379fd8
+    auto name = packageFirst->getNameCStr();
379fd8
+    auto stream = packageFirst->getStreamCStr();
379fd8
+    auto arch = packageFirst->getArchCStr();
379fd8
+
379fd8
+    for (unsigned int index = 1; index < vectorSize; ++index) {
379fd8
+        auto & package = activeModules[index];
379fd8
+        if (g_strcmp0(package->getNameCStr(), name) != 0 ||
379fd8
+            g_strcmp0(package->getStreamCStr(), stream) != 0 ||
379fd8
+            g_strcmp0(package->getArchCStr(), arch) != 0) {
379fd8
+            name = package->getNameCStr();
379fd8
+            stream = package->getStreamCStr();
379fd8
+            arch = package->getArchCStr();
379fd8
+            latest.push_back(package);
379fd8
+        }
379fd8
+    }
379fd8
+    return latest;
379fd8
 }
379fd8
 
379fd8
 void ModulePackageContainer::Impl::addVersion2Modules()
379fd8
-- 
379fd8
2.31.1
379fd8