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

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