From 511eb655fdced368a7457ee6534595a6ed2a232b Mon Sep 17 00:00:00 2001 From: Pavla Kratochvilova Date: Mon, 12 Feb 2024 09:54:51 +0100 Subject: [PATCH] modules: Report problems with switching module streams --- include/libdnf5/base/goal_elements.hpp | 3 ++- libdnf5/base/goal.cpp | 18 ++++++++++++++++++ libdnf5/base/log_event.cpp | 20 ++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/include/libdnf5/base/goal_elements.hpp b/include/libdnf5/base/goal_elements.hpp index 821ece9582..d232d8405f 100644 --- a/include/libdnf5/base/goal_elements.hpp +++ b/include/libdnf5/base/goal_elements.hpp @@ -114,7 +114,8 @@ enum class GoalProblem : uint32_t { /// Problem with latest modules during resolvement of module dependencies MODULE_SOLVER_ERROR_LATEST = (1 << 19), /// Error detected during resolvement of module dependencies - MODULE_SOLVER_ERROR = (1 << 20) + MODULE_SOLVER_ERROR = (1 << 20), + MODULE_CANNOT_SWITH_STREAMS = (1 << 21) }; /// Types of Goal actions diff --git a/libdnf5/base/goal.cpp b/libdnf5/base/goal.cpp index 1fe0bfbd2d..43c674e86c 100644 --- a/libdnf5/base/goal.cpp +++ b/libdnf5/base/goal.cpp @@ -2319,6 +2319,24 @@ base::Transaction Goal::resolve() { module::ModuleSack & module_sack = *p_impl->base->get_module_sack(); ret |= p_impl->add_module_specs_to_goal(transaction); + + // Check for switched module streams + if (!p_impl->base->get_config().get_module_stream_switch_option().get_value()) { + auto switched_streams = module_sack.p_impl->module_db->get_all_newly_switched_streams(); + if (!switched_streams.empty()) { + for (auto item : switched_streams) { + transaction.p_impl->add_resolve_log( + GoalAction::ENABLE, + GoalProblem::MODULE_CANNOT_SWITH_STREAMS, + GoalJobSettings(), + libdnf5::transaction::TransactionItemType::MODULE, + item.first, + {"0:" + item.second.first, "1:" + item.second.second}, + libdnf5::Logger::Level::ERROR); + } + ret |= GoalProblem::MODULE_CANNOT_SWITH_STREAMS; + } + } // Resolve modules auto result = module_sack.resolve_active_module_items(); auto module_solver_problems = result.first; diff --git a/libdnf5/base/log_event.cpp b/libdnf5/base/log_event.cpp index d948a93a2f..9592bfe683 100644 --- a/libdnf5/base/log_event.cpp +++ b/libdnf5/base/log_event.cpp @@ -269,6 +269,26 @@ std::string LogEvent::to_string( ret.append(utils::sformat(_("Modular dependency problems with the defaults:\n"))); return ret.append(solver_problems->to_string()); } + case GoalProblem::MODULE_CANNOT_SWITH_STREAMS: { + std::string original_stream; + std::string new_stream; + for (const auto & module_stream : additional_data) { + const auto pos = module_stream.find(":"); + if (module_stream.substr(0, pos) == "0") { + original_stream = module_stream.substr(pos + 1); + } else { + new_stream = module_stream.substr(pos + 1); + } + } + ret.append(utils::sformat( + _("The operation would result in switching of module '{0}' stream '{1}' to stream '{2}'\n"), + *spec, + original_stream, + new_stream)); + return ret.append( + _("Error: It is not possible to switch enabled streams of a module unless explicitly enabled via " + "configuration option module_stream_switch.")); + } } return ret; }