Skip to content

Commit

Permalink
modules: Don't run infinitely when enabling dependent modules and mod…
Browse files Browse the repository at this point in the history
…ule 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.
  • Loading branch information
pkratoch authored and ppisar committed Nov 16, 2023
1 parent 1d30002 commit 057da52
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion libdnf5/module/module_sack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

#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"
Expand Down Expand Up @@ -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();
Expand All @@ -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 &) {
Expand All @@ -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.");
}


Expand Down

0 comments on commit 057da52

Please sign in to comment.