Skip to content

Commit

Permalink
Install oneof module items on module enable
Browse files Browse the repository at this point in the history
Like in DNF 5, we should require oneof the module items when a module is
enabled. This way, a clearer error message is printed when trying to
enable a module for an incompatible architecture.

Adds Goal::install_queue(IdQueue * id_queue, bool optional), like the
Goall::add_install we have in DNF 5.

For https://issues.redhat.com/browse/RHEL-16580.
  • Loading branch information
evan-goode committed Apr 23, 2024
1 parent 0120e70 commit 6d4d7b8
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
17 changes: 16 additions & 1 deletion libdnf/goal/Goal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ extern "C" {
#include "../sack/selector.hpp"
#include "../utils/bgettext/bgettext-lib.h"
#include "../utils/tinyformat/tinyformat.hpp"
#include "IdQueue.hpp"
#include "../utils/filesystem.hpp"

namespace {
Expand Down Expand Up @@ -798,6 +797,22 @@ Goal::install(DnfPackage *new_pkg, bool optional)
packageToJob(new_pkg, &pImpl->staging, solverActions);
}

void
Goal::install_queue(IdQueue * id_queue, bool optional)
{
int solver_actions = SOLVER_INSTALL;
if (optional) {
solver_actions |= SOLVER_WEAK;
}
pImpl->actions = static_cast<DnfGoalActions>(pImpl->actions | DNF_INSTALL|DNF_ALLOW_DOWNGRADE);

dnf_sack_recompute_considered(getSack());
dnf_sack_make_provides_ready(getSack());

Id what = pool_queuetowhatprovides(dnf_sack_get_pool(getSack()), id_queue->getQueue());
queue_push2(&pImpl->staging, SOLVER_SOLVABLE_ONE_OF|SOLVER_SETARCH|SOLVER_SETEVR|solver_actions, what);
}

void
Goal::lock(DnfPackage *pkg)
{
Expand Down
2 changes: 2 additions & 0 deletions libdnf/goal/Goal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "../error.hpp"
#include "../hy-goal.h"
#include "../hy-package.h"
#include "IdQueue.hpp"

namespace libdnf {

Expand Down Expand Up @@ -74,6 +75,7 @@ struct Goal {
*/
void erase(HySelector sltr, int flags);
void install(DnfPackage *new_pkg, bool optional);
void install_queue(IdQueue * id_queue, bool optional);
void lock(DnfPackage *new_pkg);
void favor(DnfPackage *new_pkg);
void add_exclude_from_weak(const DnfPackageSet & pset);
Expand Down
25 changes: 25 additions & 0 deletions libdnf/module/ModulePackageContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ class ModulePackageContainer::Impl {
std::map<std::string, std::string> moduleDefaults;
std::vector<std::tuple<LibsolvRepo *, ModulemdModuleStream *, std::string>> modulesV2;

std::vector<std::tuple<std::string, std::string, IdQueue>> modules_to_enable;

bool isEnabled(const std::string &name, const std::string &stream);
};

Expand Down Expand Up @@ -575,6 +577,19 @@ ModulePackageContainer::enable(const ModulePackage * module, const bool count)
return enable(module->getName(), module->getStream(), count);
}

bool
ModulePackageContainer::enable(const std::string & name, const std::string & stream, const std::vector<ModulePackage *> & module_packages, const bool count)
{
bool changed{false};
IdQueue queue;
for (const auto & module_package : module_packages) {
changed |= enable(module_package, count);
queue.pushBack(module_package->getId());
}
pImpl->modules_to_enable.push_back(std::make_tuple(name, stream, queue));
return changed;
}

/**
* @brief Mark module as not part of an enabled stream.
*/
Expand Down Expand Up @@ -701,6 +716,15 @@ ModulePackageContainer::Impl::moduleSolve(const std::vector<ModulePackage *> & m
goal.install(&selector, optional);
goalWeak.install(&selector, true);
}

for (auto & module_to_enable : modules_to_enable) {
const auto & name = std::get<0>(module_to_enable);
auto & queue = std::get<2>(module_to_enable);
const bool optional = persistor->getState(name) == ModuleState::DEFAULT;
goal.install_queue(&queue, optional);
goalWeak.install_queue(&queue, true);
}

auto ret = goal.run(static_cast<DnfGoalActions>(DNF_IGNORE_WEAK | DNF_FORCE_BEST));
if (debugSolver) {
goal.writeDebugdata("debugdata/modules");
Expand Down Expand Up @@ -1208,6 +1232,7 @@ void ModulePackageContainer::save()

void ModulePackageContainer::rollback()
{
pImpl->modules_to_enable.clear();
pImpl->persistor->rollback();
}

Expand Down
21 changes: 18 additions & 3 deletions libdnf/module/ModulePackageContainer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ struct ModulePackageContainer
std::vector<ModulePackage *> requiresModuleEnablement(const libdnf::PackageSet & packages);

/**
* @brief Enable module stream. Return true if requested change realy triggers a change in
* @brief Enable module stream. Return true if requested change really triggers a change in
* the persistor.
* When the count parameter is set to false the change will not count towards the limit of
* module state modifications.
Expand All @@ -158,10 +158,25 @@ struct ModulePackageContainer
*
* @return bool
*/
bool enable(const std::string &name, const std::string &stream, const bool count = true);
bool enable(const std::string & name, const std::string & stream, const bool count = true);

/**
* @brief Enable module stream. Return true if requested changes realy triggers a change in
* @brief Enable module stream with an explicit set of module packages.
* Return true only if requested change really reiggers a change in the
* persistor.
* When the count parameter is set to false the change will not count towards the limit of
* module state modifications.
* It can throw ModulePackageContainer::EnableMultipleStreamsException or
* ModulePackageContainer::NoModuleException exceprion if module do not exist
*
* @return bool
*/
bool enable(const std::string &name, const std::string &stream,
const std::vector<ModulePackage *> & module_packages,
const bool count = true);

/**
* @brief Enable module stream. Return true if requested changes really triggers a change in
* the persistor.
* When the count parameter is set to false the change will not count towards the limit of
* module state modifications.
Expand Down

0 comments on commit 6d4d7b8

Please sign in to comment.