From 057da52ac1617133aed0b01bd511c78874838729 Mon Sep 17 00:00:00 2001 From: Pavla Kratochvilova Date: Tue, 14 Nov 2023 15:01:08 +0100 Subject: [PATCH] modules: Don't run infinitely when enabling dependent modules and module is not found This situation shouldn't happen, because the modules were resolved at this point and all necessary dependencies should be among the active modules. However, if there is a bug, it's better to throw an error than to be stuck in an infinite loop. --- libdnf5/module/module_sack.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libdnf5/module/module_sack.cpp b/libdnf5/module/module_sack.cpp index 6e1ab0111..8746e8476 100644 --- a/libdnf5/module/module_sack.cpp +++ b/libdnf5/module/module_sack.cpp @@ -27,6 +27,7 @@ along with libdnf. If not, see . #include "libdnf5/base/base.hpp" #include "libdnf5/base/base_weak.hpp" +#include "libdnf5/common/exception.hpp" #include "libdnf5/module/module_errors.hpp" #include "libdnf5/module/module_item.hpp" #include "libdnf5/module/module_query.hpp" @@ -425,7 +426,9 @@ void ModuleSack::Impl::enable_dependent_modules() { } // While there are some modules to enable, search for corresponding active module items and enable them + process their dependencies - while (!modules_to_enable.empty()) { + bool new_modules_to_enable = true; + while (new_modules_to_enable && !modules_to_enable.empty()) { + new_modules_to_enable = false; for (const auto & active_module : active_modules) { const auto & module_name = active_module.second->get_name(); const auto & module_stream = active_module.second->get_stream(); @@ -441,6 +444,7 @@ void ModuleSack::Impl::enable_dependent_modules() { for (const auto & dependency : active_module.second->get_module_dependencies()) { try { if (module_db->get_status(dependency.get_module_name()) == ModuleStatus::AVAILABLE) { + new_modules_to_enable = true; modules_to_enable.emplace(dependency.get_module_name(), dependency.get_streams()); } } catch (NoModuleError &) { @@ -450,6 +454,8 @@ void ModuleSack::Impl::enable_dependent_modules() { } } } + libdnf_assert( + modules_to_enable.empty(), "Some enabled modules or their dependencies were not found among active modules."); }