Skip to content

Commit

Permalink
ModulePackage: add getDefaultProfile()
Browse files Browse the repository at this point in the history
This is useful if the profile is unspecified by the user. Match the dnf
semantic of auto-defaulting to the only profile there is.
  • Loading branch information
jlebon committed Apr 19, 2021
1 parent 63afb98 commit 2a90b8d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions libdnf/module/ModulePackage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,26 @@ ModulePackage::getProfiles(const std::string &name) const
return result_profiles;
}

ModuleProfile
ModulePackage::getDefaultProfile() const
{
//TODO(amatej): replace with
//char ** profiles = modulemd_module_stream_v2_search_profiles((ModulemdModuleStreamV2 *) mdStream, profileNameCStr);
char ** profiles = modulemd_module_stream_v2_get_profile_names_as_strv((ModulemdModuleStreamV2 *) mdStream);
if (g_strv_length (profiles) == 1) {
return ModuleProfile(modulemd_module_stream_v2_get_profile((ModulemdModuleStreamV2 *) mdStream, profiles[0]));
}

for (char **iter = profiles; iter && *iter; iter++) {
auto profile = ModuleProfile(modulemd_module_stream_v2_get_profile((ModulemdModuleStreamV2 *) mdStream, *iter));
if (profile.isDefault()) {
return profile;
}
}

throw std::runtime_error("No default profile found for " + getFullIdentifier());
}

/**
* @brief Return list of ModuleProfiles.
*
Expand Down
1 change: 1 addition & 0 deletions libdnf/module/ModulePackage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class ModulePackage // TODO inherit in future; : public Package
*/
std::vector<ModuleProfile> getProfiles(const std::string &name) const;
std::vector<ModuleProfile> getProfiles() const;
ModuleProfile getDefaultProfile() const;

std::vector<ModuleDependencies> getModuleDependencies() const;

Expand Down

0 comments on commit 2a90b8d

Please sign in to comment.