Skip to content

Commit

Permalink
modules: Store if profile is default in ModuleProfile object
Browse files Browse the repository at this point in the history
  • Loading branch information
pkratoch committed Oct 26, 2023
1 parent 07b2a7f commit d9ea5d7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
3 changes: 2 additions & 1 deletion include/libdnf5/module/module_profile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ class ModuleProfile {
friend class ModuleItem;

// @replaces libdnf:module:modulemd/ModuleProfile.hpp:ctor:ModuleProfile.ModuleProfile(ModulemdProfile * profile)
ModuleProfile(_ModulemdProfile * profile);
ModuleProfile(_ModulemdProfile * profile, const bool is_default);

// @replaces libdnf:module:modulemd/ModuleProfile.hpp:attribute:ModuleProfile.profile
_ModulemdProfile * profile{nullptr};
bool is_default_profile = false;
};


Expand Down
7 changes: 6 additions & 1 deletion libdnf5/module/module_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,14 @@ std::vector<std::string> ModuleItem::get_demodularized_rpms() const {
std::vector<ModuleProfile> ModuleItem::get_profiles_internal(const char * name) const {
std::vector<ModuleProfile> result_profiles;
GPtrArray * profiles = modulemd_module_stream_v2_search_profiles((ModulemdModuleStreamV2 *)md_stream, name);
const auto & default_profiles = module_sack->get_default_profiles(get_name(), get_stream());

for (unsigned int i = 0; i < profiles->len; i++) {
result_profiles.push_back(ModuleProfile(static_cast<ModulemdProfile *>(g_ptr_array_index(profiles, i))));
const auto & modulemd_profile = static_cast<ModulemdProfile *>(g_ptr_array_index(profiles, i));
result_profiles.push_back(ModuleProfile(
modulemd_profile,
std::find(default_profiles.begin(), default_profiles.end(), modulemd_profile_get_name(modulemd_profile)) !=
default_profiles.end()));
}

g_ptr_array_free(profiles, true);
Expand Down
9 changes: 7 additions & 2 deletions libdnf5/module/module_profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,16 @@ bool ModuleProfile::is_default() const {
}


ModuleProfile::ModuleProfile(ModulemdProfile * profile) : profile(profile) {
ModuleProfile::ModuleProfile(ModulemdProfile * profile, const bool is_default)
: profile(profile),
is_default_profile(is_default) {
g_object_ref(profile);
}


ModuleProfile::ModuleProfile(const ModuleProfile & src) : profile(src.profile) {
ModuleProfile::ModuleProfile(const ModuleProfile & src)
: profile(src.profile),
is_default_profile(src.is_default_profile) {
if (profile != nullptr) {
g_object_ref(profile);
}
Expand All @@ -84,6 +88,7 @@ ModuleProfile & ModuleProfile::operator=(const ModuleProfile & src) {
if (this != &src) {
g_object_unref(profile);
profile = src.profile;
is_default_profile = src.is_default_profile;
if (profile != nullptr) {
g_object_ref(profile);
}
Expand Down

0 comments on commit d9ea5d7

Please sign in to comment.