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