From 525f3da2c88b3384a31057b7c9bc180e35745f03 Mon Sep 17 00:00:00 2001 From: Marek Blaha Date: Fri, 31 Mar 2023 12:33:43 +0200 Subject: [PATCH] solv_repo: Create group solvable from system state Creates a minimal group solvable from information contained in the system state - groupid and a list of installed packages from the group. --- libdnf/repo/solv_repo.cpp | 36 ++++++++++++++++++++++++++++++++++++ libdnf/repo/solv_repo.hpp | 6 ++++++ 2 files changed, 42 insertions(+) diff --git a/libdnf/repo/solv_repo.cpp b/libdnf/repo/solv_repo.cpp index e2171441f..2fc4c74f0 100644 --- a/libdnf/repo/solv_repo.cpp +++ b/libdnf/repo/solv_repo.cpp @@ -711,4 +711,40 @@ bool SolvRepo::read_group_solvable_from_xml(const std::string & path) { return read_success; } +void SolvRepo::create_group_solvable(const std::string & groupid, const libdnf::system::GroupState & state) { + solv::Pool & pool = static_cast(get_comps_pool(base)); + libdnf_assert( + comps_repo == (*pool)->installed, "SolvRepo::create_group_solvable() call enabled only for @System repo."); + + // create a new solvable for the group + auto group_solvable_id = repo_add_solvable(comps_repo); + Solvable * group_solvable = pool.id2solvable(group_solvable_id); + + // Information about group contained in the system state is very limited. + // We have only repoid and list of installed packages. + + // Set id with proper prefix + group_solvable->name = pool.str2id(("group:" + groupid).c_str(), 1); + // Set noarch and empty evr + group_solvable->arch = ARCH_NOARCH; + group_solvable->evr = ID_EMPTY; + // Make the new group provide it's own id + group_solvable->dep_provides = repo_addid_dep( + comps_repo, group_solvable->dep_provides, pool.rel2id(group_solvable->name, group_solvable->evr, REL_EQ, 1), 0); + + // Add group packages + for (const auto & pkg_name : state.packages) { + auto pkg_id = pool.str2id(pkg_name.c_str(), 1); + Id type = SOLVABLE_RECOMMENDS; + repo_add_idarray(comps_repo, group_solvable_id, type, pkg_id); + } + + Repodata * data = repo_last_repodata(comps_repo); + + // Mark the repo as user-visible + repodata_set_void(data, group_solvable_id, SOLVABLE_ISVISIBLE); + + repodata_internalize(data); +} + } //namespace libdnf::repo diff --git a/libdnf/repo/solv_repo.hpp b/libdnf/repo/solv_repo.hpp index 4da5e9cf6..cb2afc796 100644 --- a/libdnf/repo/solv_repo.hpp +++ b/libdnf/repo/solv_repo.hpp @@ -98,6 +98,12 @@ class SolvRepo { std::vector & get_groups_missing_xml() { return groups_missing_xml; }; + /// Create a group solvable based on what's available in system state. Used in + /// case we are not able to load metadata from xml file. + /// @param groupid Id of the group + /// @param state group state from the system state + void create_group_solvable(const std::string & groupid, const libdnf::system::GroupState & state); + /// Read comps group solvable from its xml file. /// @param path Path to xml file. /// @return True if the group was successfully read.