Skip to content

Commit

Permalink
solv_repo: Create group solvable from system state
Browse files Browse the repository at this point in the history
Creates a minimal group solvable from information contained in the
system state - groupid and a list of installed packages from the group.
  • Loading branch information
m-blaha committed Mar 31, 2023
1 parent 882cab8 commit 525f3da
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
36 changes: 36 additions & 0 deletions libdnf/repo/solv_repo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<solv::Pool &>(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
6 changes: 6 additions & 0 deletions libdnf/repo/solv_repo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ class SolvRepo {

std::vector<std::string> & 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.
Expand Down

0 comments on commit 525f3da

Please sign in to comment.