From 0bc9975a7f6deab7f6ee1cd0b3bceab145bbb35c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= Date: Tue, 26 Mar 2024 09:25:34 +0100 Subject: [PATCH] Use new overload of `update_and_load_enabled_repos(...)` It allows hiding of `libdnf5::repo::Repo::load()`. Also simplifies handling of which repos to load in dnf5 context. --- dnf5-plugins/automatic_plugin/automatic.cpp | 3 +- dnf5-plugins/builddep_plugin/builddep.cpp | 3 +- dnf5-plugins/changelog_plugin/changelog.cpp | 3 +- .../needs_restarting.cpp | 3 +- .../repoclosure_plugin/repoclosure.cpp | 3 +- .../commands/advisory/advisory_subcommand.cpp | 3 +- dnf5/commands/autoremove/autoremove.cpp | 3 +- dnf5/commands/check-upgrade/check-upgrade.cpp | 3 +- dnf5/commands/distro-sync/distro-sync.cpp | 3 +- dnf5/commands/downgrade/downgrade.cpp | 3 +- dnf5/commands/download/download.cpp | 8 ++--- .../commands/environment/environment_info.cpp | 3 +- .../commands/environment/environment_list.cpp | 3 +- dnf5/commands/group/group_install.cpp | 3 +- dnf5/commands/group/group_list.cpp | 3 +- dnf5/commands/group/group_remove.cpp | 3 +- dnf5/commands/group/group_upgrade.cpp | 3 +- dnf5/commands/install/install.cpp | 3 +- dnf5/commands/leaves/leaves.cpp | 3 +- dnf5/commands/list/list.cpp | 12 +++---- dnf5/commands/makecache/makecache.cpp | 2 -- dnf5/commands/module/module_disable.cpp | 3 +- dnf5/commands/module/module_enable.cpp | 3 +- dnf5/commands/module/module_list.cpp | 3 +- dnf5/commands/module/module_reset.cpp | 3 +- dnf5/commands/provides/provides.cpp | 3 +- dnf5/commands/reinstall/reinstall.cpp | 3 +- dnf5/commands/remove/remove.cpp | 3 +- dnf5/commands/repo/repo_info.cpp | 2 +- dnf5/commands/repoquery/repoquery.cpp | 27 +++++++++------ dnf5/commands/repoquery/repoquery.hpp | 2 -- dnf5/commands/search/search.cpp | 3 +- dnf5/commands/swap/swap.cpp | 3 +- dnf5/commands/upgrade/upgrade.cpp | 3 +- dnf5/commands/versionlock/versionlock_add.cpp | 3 +- .../versionlock/versionlock_exclude.cpp | 2 +- dnf5/context.cpp | 34 +++++++++---------- dnf5/include/dnf5/context.hpp | 11 +++--- dnf5/main.cpp | 10 +----- dnf5daemon-server/session.cpp | 13 +++++-- 40 files changed, 89 insertions(+), 121 deletions(-) diff --git a/dnf5-plugins/automatic_plugin/automatic.cpp b/dnf5-plugins/automatic_plugin/automatic.cpp index b5eb4caece..e2948fdeea 100644 --- a/dnf5-plugins/automatic_plugin/automatic.cpp +++ b/dnf5-plugins/automatic_plugin/automatic.cpp @@ -306,10 +306,9 @@ void AutomaticCommand::pre_configure() { void AutomaticCommand::configure() { auto & context = get_context(); - context.set_load_system_repo(true); context.update_repo_metadata_from_advisory_options( {}, config_automatic.config_commands.upgrade_type.get_value() == "security", false, false, false, {}, {}, {}); - context.set_load_available_repos(Context::LoadAvailableRepos::ENABLED); + context.set_load_enabled_repos({libdnf5::repo::Repo::Type::AVAILABLE, libdnf5::repo::Repo::Type::SYSTEM}); wait_for_network(); } diff --git a/dnf5-plugins/builddep_plugin/builddep.cpp b/dnf5-plugins/builddep_plugin/builddep.cpp index 682e5fe167..5f2dc3d053 100644 --- a/dnf5-plugins/builddep_plugin/builddep.cpp +++ b/dnf5-plugins/builddep_plugin/builddep.cpp @@ -96,8 +96,7 @@ void BuildDepCommand::configure() { } auto & context = get_context(); - context.set_load_system_repo(true); - context.set_load_available_repos(Context::LoadAvailableRepos::ENABLED); + context.set_load_enabled_repos({libdnf5::repo::Repo::Type::AVAILABLE, libdnf5::repo::Repo::Type::SYSTEM}); } void BuildDepCommand::parse_builddep_specs(int specs_count, const char * const specs[]) { diff --git a/dnf5-plugins/changelog_plugin/changelog.cpp b/dnf5-plugins/changelog_plugin/changelog.cpp index d9e22db205..3316840aac 100644 --- a/dnf5-plugins/changelog_plugin/changelog.cpp +++ b/dnf5-plugins/changelog_plugin/changelog.cpp @@ -108,8 +108,7 @@ void ChangelogCommand::set_argument_parser() { void ChangelogCommand::configure() { auto & context = get_context(); - context.set_load_system_repo(true); - context.set_load_available_repos(Context::LoadAvailableRepos::ENABLED); + context.set_load_enabled_repos({libdnf5::repo::Repo::Type::AVAILABLE, libdnf5::repo::Repo::Type::SYSTEM}); context.base.get_config().get_optional_metadata_types_option().add( libdnf5::Option::Priority::RUNTIME, libdnf5::OPTIONAL_METADATA_TYPES); } diff --git a/dnf5-plugins/needs_restarting_plugin/needs_restarting.cpp b/dnf5-plugins/needs_restarting_plugin/needs_restarting.cpp index d179d580ed..89a9ac1322 100644 --- a/dnf5-plugins/needs_restarting_plugin/needs_restarting.cpp +++ b/dnf5-plugins/needs_restarting_plugin/needs_restarting.cpp @@ -78,9 +78,8 @@ void NeedsRestartingCommand::set_argument_parser() { void NeedsRestartingCommand::configure() { auto & context = get_context(); - context.set_load_system_repo(true); - context.set_load_available_repos(Context::LoadAvailableRepos::ENABLED); + context.set_load_enabled_repos({libdnf5::repo::Repo::Type::AVAILABLE, libdnf5::repo::Repo::Type::SYSTEM}); const std::set metadata_types{libdnf5::METADATA_TYPE_FILELISTS, libdnf5::METADATA_TYPE_UPDATEINFO}; context.base.get_config().get_optional_metadata_types_option().add( diff --git a/dnf5-plugins/repoclosure_plugin/repoclosure.cpp b/dnf5-plugins/repoclosure_plugin/repoclosure.cpp index eff66aa437..f878c05b4e 100644 --- a/dnf5-plugins/repoclosure_plugin/repoclosure.cpp +++ b/dnf5-plugins/repoclosure_plugin/repoclosure.cpp @@ -97,11 +97,10 @@ void RepoclosureCommand::set_argument_parser() { void RepoclosureCommand::configure() { auto & context = get_context(); - context.set_load_system_repo(false); // filelists needed because there are packages in repos with file requirements context.base.get_config().get_optional_metadata_types_option().add_item( libdnf5::Option::Priority::RUNTIME, libdnf5::METADATA_TYPE_FILELISTS); - context.set_load_available_repos(Context::LoadAvailableRepos::ENABLED); + context.set_load_enabled_repos({libdnf5::repo::Repo::Type::AVAILABLE}); } void RepoclosureCommand::run() { diff --git a/dnf5/commands/advisory/advisory_subcommand.cpp b/dnf5/commands/advisory/advisory_subcommand.cpp index 0d3107648d..193c6e728e 100644 --- a/dnf5/commands/advisory/advisory_subcommand.cpp +++ b/dnf5/commands/advisory/advisory_subcommand.cpp @@ -72,8 +72,7 @@ void AdvisorySubCommand::add_running_kernel_packages(libdnf5::Base & base, libdn void AdvisorySubCommand::configure() { auto & context = get_context(); - context.set_load_system_repo(true); - context.set_load_available_repos(Context::LoadAvailableRepos::ENABLED); + context.set_load_enabled_repos({libdnf5::repo::Repo::Type::AVAILABLE, libdnf5::repo::Repo::Type::SYSTEM}); context.base.get_config().get_optional_metadata_types_option().add_item( libdnf5::Option::Priority::RUNTIME, libdnf5::METADATA_TYPE_UPDATEINFO); } diff --git a/dnf5/commands/autoremove/autoremove.cpp b/dnf5/commands/autoremove/autoremove.cpp index eba1a3eb14..882ec502ec 100644 --- a/dnf5/commands/autoremove/autoremove.cpp +++ b/dnf5/commands/autoremove/autoremove.cpp @@ -39,8 +39,7 @@ void AutoremoveCommand::set_argument_parser() { void AutoremoveCommand::configure() { auto & context = get_context(); - context.set_load_system_repo(true); - context.set_load_available_repos(Context::LoadAvailableRepos::NONE); + context.set_load_enabled_repos({libdnf5::repo::Repo::Type::SYSTEM}); } void AutoremoveCommand::run() { diff --git a/dnf5/commands/check-upgrade/check-upgrade.cpp b/dnf5/commands/check-upgrade/check-upgrade.cpp index b1c0b2e319..2d68b90309 100644 --- a/dnf5/commands/check-upgrade/check-upgrade.cpp +++ b/dnf5/commands/check-upgrade/check-upgrade.cpp @@ -80,8 +80,7 @@ void CheckUpgradeCommand::set_argument_parser() { void CheckUpgradeCommand::configure() { auto & context = get_context(); context.update_repo_metadata_from_specs(pkg_specs); - context.set_load_system_repo(true); - context.set_load_available_repos(Context::LoadAvailableRepos::ENABLED); + context.set_load_enabled_repos({libdnf5::repo::Repo::Type::AVAILABLE, libdnf5::repo::Repo::Type::SYSTEM}); if (changelogs->get_value()) { context.base.get_config().get_optional_metadata_types_option().add( libdnf5::Option::Priority::RUNTIME, libdnf5::METADATA_TYPE_OTHER); diff --git a/dnf5/commands/distro-sync/distro-sync.cpp b/dnf5/commands/distro-sync/distro-sync.cpp index 2c92c747f2..8e23ea00e9 100644 --- a/dnf5/commands/distro-sync/distro-sync.cpp +++ b/dnf5/commands/distro-sync/distro-sync.cpp @@ -56,8 +56,7 @@ void DistroSyncCommand::set_argument_parser() { void DistroSyncCommand::configure() { auto & context = get_context(); - context.set_load_system_repo(true); - context.set_load_available_repos(Context::LoadAvailableRepos::ENABLED); + context.set_load_enabled_repos({libdnf5::repo::Repo::Type::AVAILABLE, libdnf5::repo::Repo::Type::SYSTEM}); } void DistroSyncCommand::run() { diff --git a/dnf5/commands/downgrade/downgrade.cpp b/dnf5/commands/downgrade/downgrade.cpp index 5aaa279ca6..5d881046fb 100644 --- a/dnf5/commands/downgrade/downgrade.cpp +++ b/dnf5/commands/downgrade/downgrade.cpp @@ -60,8 +60,7 @@ void DowngradeCommand::set_argument_parser() { void DowngradeCommand::configure() { auto & context = get_context(); - context.set_load_system_repo(true); - context.set_load_available_repos(Context::LoadAvailableRepos::ENABLED); + context.set_load_enabled_repos({libdnf5::repo::Repo::Type::AVAILABLE, libdnf5::repo::Repo::Type::SYSTEM}); } void DowngradeCommand::run() { diff --git a/dnf5/commands/download/download.cpp b/dnf5/commands/download/download.cpp index 7f4e690759..b9873bab81 100644 --- a/dnf5/commands/download/download.cpp +++ b/dnf5/commands/download/download.cpp @@ -164,22 +164,22 @@ void DownloadCommand::configure() { pkg_specs.push_back(option->get_value()); } + std::vector which_repos_to_load = {libdnf5::repo::Repo::Type::AVAILABLE}; + context.update_repo_metadata_from_specs(pkg_specs); if (resolve_option->get_value() && !alldeps_option->get_value()) { - context.set_load_system_repo(true); + which_repos_to_load.push_back(libdnf5::repo::Repo::Type::SYSTEM); } else if (!resolve_option->get_value() && alldeps_option->get_value()) { throw libdnf5::cli::ArgumentParserMissingDependentArgumentError( //TODO(jrohel): Add support for requiring an argument by another argument in ArgumentParser? M_("Option \"--alldeps\" should be used with \"--resolve\"")); - } else { - context.set_load_system_repo(false); } if (srpm_option->get_value()) { context.base.get_repo_sack()->enable_source_repos(); } - context.set_load_available_repos(Context::LoadAvailableRepos::ENABLED); + context.set_load_enabled_repos(which_repos_to_load); // Default destination for downloaded rpms is the current directory context.base.get_config().get_destdir_option().set(libdnf5::Option::Priority::PLUGINDEFAULT, "."); } diff --git a/dnf5/commands/environment/environment_info.cpp b/dnf5/commands/environment/environment_info.cpp index 622cb942ee..a73d5f54b3 100644 --- a/dnf5/commands/environment/environment_info.cpp +++ b/dnf5/commands/environment/environment_info.cpp @@ -43,8 +43,7 @@ void EnvironmentInfoCommand::set_argument_parser() { void EnvironmentInfoCommand::configure() { auto & context = get_context(); - context.set_load_system_repo(true); - context.set_load_available_repos(Context::LoadAvailableRepos::ENABLED); + context.set_load_enabled_repos({libdnf5::repo::Repo::Type::AVAILABLE, libdnf5::repo::Repo::Type::SYSTEM}); context.base.get_config().get_optional_metadata_types_option().add_item( libdnf5::Option::Priority::RUNTIME, libdnf5::METADATA_TYPE_COMPS); } diff --git a/dnf5/commands/environment/environment_list.cpp b/dnf5/commands/environment/environment_list.cpp index 5d875bf6bc..593511c022 100644 --- a/dnf5/commands/environment/environment_list.cpp +++ b/dnf5/commands/environment/environment_list.cpp @@ -41,8 +41,7 @@ void EnvironmentListCommand::set_argument_parser() { void EnvironmentListCommand::configure() { auto & context = get_context(); - context.set_load_system_repo(true); - context.set_load_available_repos(Context::LoadAvailableRepos::ENABLED); + context.set_load_enabled_repos({libdnf5::repo::Repo::Type::AVAILABLE, libdnf5::repo::Repo::Type::SYSTEM}); context.base.get_config().get_optional_metadata_types_option().add_item( libdnf5::Option::Priority::RUNTIME, libdnf5::METADATA_TYPE_COMPS); } diff --git a/dnf5/commands/group/group_install.cpp b/dnf5/commands/group/group_install.cpp index 8a8ef401c6..f49982f273 100644 --- a/dnf5/commands/group/group_install.cpp +++ b/dnf5/commands/group/group_install.cpp @@ -47,8 +47,7 @@ void GroupInstallCommand::set_argument_parser() { void GroupInstallCommand::configure() { auto & context = get_context(); - context.set_load_system_repo(true); - context.set_load_available_repos(Context::LoadAvailableRepos::ENABLED); + context.set_load_enabled_repos({libdnf5::repo::Repo::Type::AVAILABLE, libdnf5::repo::Repo::Type::SYSTEM}); context.base.get_config().get_optional_metadata_types_option().add_item( libdnf5::Option::Priority::RUNTIME, libdnf5::METADATA_TYPE_COMPS); } diff --git a/dnf5/commands/group/group_list.cpp b/dnf5/commands/group/group_list.cpp index b28f485828..76ef1dbb02 100644 --- a/dnf5/commands/group/group_list.cpp +++ b/dnf5/commands/group/group_list.cpp @@ -43,8 +43,7 @@ void GroupListCommand::set_argument_parser() { void GroupListCommand::configure() { auto & context = get_context(); - context.set_load_system_repo(true); - context.set_load_available_repos(Context::LoadAvailableRepos::ENABLED); + context.set_load_enabled_repos({libdnf5::repo::Repo::Type::AVAILABLE, libdnf5::repo::Repo::Type::SYSTEM}); context.base.get_config().get_optional_metadata_types_option().add_item( libdnf5::Option::Priority::RUNTIME, libdnf5::METADATA_TYPE_COMPS); } diff --git a/dnf5/commands/group/group_remove.cpp b/dnf5/commands/group/group_remove.cpp index 4813fc0174..f88c4e9f44 100644 --- a/dnf5/commands/group/group_remove.cpp +++ b/dnf5/commands/group/group_remove.cpp @@ -39,8 +39,7 @@ void GroupRemoveCommand::set_argument_parser() { void GroupRemoveCommand::configure() { auto & context = get_context(); - context.set_load_system_repo(true); - context.set_load_available_repos(Context::LoadAvailableRepos::ENABLED); + context.set_load_enabled_repos({libdnf5::repo::Repo::Type::AVAILABLE, libdnf5::repo::Repo::Type::SYSTEM}); context.base.get_config().get_optional_metadata_types_option().add_item( libdnf5::Option::Priority::RUNTIME, libdnf5::METADATA_TYPE_COMPS); } diff --git a/dnf5/commands/group/group_upgrade.cpp b/dnf5/commands/group/group_upgrade.cpp index 8d3f7301d9..01891420fd 100644 --- a/dnf5/commands/group/group_upgrade.cpp +++ b/dnf5/commands/group/group_upgrade.cpp @@ -43,8 +43,7 @@ void GroupUpgradeCommand::set_argument_parser() { void GroupUpgradeCommand::configure() { auto & context = get_context(); - context.set_load_system_repo(true); - context.set_load_available_repos(Context::LoadAvailableRepos::ENABLED); + context.set_load_enabled_repos({libdnf5::repo::Repo::Type::AVAILABLE, libdnf5::repo::Repo::Type::SYSTEM}); context.base.get_config().get_optional_metadata_types_option().add_item( libdnf5::Option::Priority::RUNTIME, libdnf5::METADATA_TYPE_COMPS); } diff --git a/dnf5/commands/install/install.cpp b/dnf5/commands/install/install.cpp index d9a3cdca3c..2d2b0cb5e7 100644 --- a/dnf5/commands/install/install.cpp +++ b/dnf5/commands/install/install.cpp @@ -72,7 +72,6 @@ void InstallCommand::set_argument_parser() { void InstallCommand::configure() { auto & context = get_context(); context.update_repo_metadata_from_specs(pkg_specs); - context.set_load_system_repo(true); context.update_repo_metadata_from_advisory_options( advisory_name->get_value(), advisory_security->get_value(), @@ -83,7 +82,7 @@ void InstallCommand::configure() { advisory_bz->get_value(), advisory_cve->get_value()); - context.set_load_available_repos(Context::LoadAvailableRepos::ENABLED); + context.set_load_enabled_repos({libdnf5::repo::Repo::Type::AVAILABLE, libdnf5::repo::Repo::Type::SYSTEM}); } void InstallCommand::run() { diff --git a/dnf5/commands/leaves/leaves.cpp b/dnf5/commands/leaves/leaves.cpp index b335082de5..6311b4826c 100644 --- a/dnf5/commands/leaves/leaves.cpp +++ b/dnf5/commands/leaves/leaves.cpp @@ -54,8 +54,7 @@ in the group is preceded by a '-' character.)"); void LeavesCommand::configure() { auto & context = get_context(); - context.set_load_system_repo(true); - context.set_load_available_repos(Context::LoadAvailableRepos::NONE); + context.set_load_enabled_repos({libdnf5::repo::Repo::Type::SYSTEM}); } void LeavesCommand::run() { diff --git a/dnf5/commands/list/list.cpp b/dnf5/commands/list/list.cpp index b13f726801..eacfb3319f 100644 --- a/dnf5/commands/list/list.cpp +++ b/dnf5/commands/list/list.cpp @@ -109,12 +109,12 @@ void ListCommand::set_argument_parser() { void ListCommand::configure() { // TODO(mblaha): do not force expired metadata sync if not explicitly required pkg_narrow = PkgNarrow::ALL; - Context::LoadAvailableRepos load_available = Context::LoadAvailableRepos::ENABLED; - bool load_system = true; + std::vector which_repos_to_load = {libdnf5::repo::Repo::Type::AVAILABLE}; + if (available->get_value()) { pkg_narrow = PkgNarrow::AVAILABLE; } else if (installed->get_value()) { - load_available = Context::LoadAvailableRepos::NONE; + which_repos_to_load.clear(); pkg_narrow = PkgNarrow::INSTALLED; } else if (extras->get_value()) { pkg_narrow = PkgNarrow::EXTRAS; @@ -125,12 +125,12 @@ void ListCommand::configure() { } else if (upgrades->get_value()) { pkg_narrow = PkgNarrow::UPGRADES; } else if (autoremove->get_value()) { - load_available = Context::LoadAvailableRepos::NONE; + which_repos_to_load.clear(); pkg_narrow = PkgNarrow::AUTOREMOVE; } auto & context = get_context(); - context.set_load_available_repos(load_available); - context.set_load_system_repo(load_system); + which_repos_to_load.push_back(libdnf5::repo::Repo::Type::SYSTEM); + context.set_load_enabled_repos(which_repos_to_load); } std::unique_ptr ListCommand::create_output() { diff --git a/dnf5/commands/makecache/makecache.cpp b/dnf5/commands/makecache/makecache.cpp index 3ad2d87bc2..3ceb6a6f90 100644 --- a/dnf5/commands/makecache/makecache.cpp +++ b/dnf5/commands/makecache/makecache.cpp @@ -57,8 +57,6 @@ void MakeCacheCommand::run() { return; } - ctx.load_repos(false); - std::cout << "Metadata cache created." << std::endl; } diff --git a/dnf5/commands/module/module_disable.cpp b/dnf5/commands/module/module_disable.cpp index 1c2cfba3d0..02c042d00f 100644 --- a/dnf5/commands/module/module_disable.cpp +++ b/dnf5/commands/module/module_disable.cpp @@ -50,8 +50,7 @@ void ModuleDisableCommand::set_argument_parser() { void ModuleDisableCommand::configure() { auto & context = get_context(); - context.set_load_system_repo(true); - context.set_load_available_repos(Context::LoadAvailableRepos::ENABLED); + context.set_load_enabled_repos({libdnf5::repo::Repo::Type::AVAILABLE, libdnf5::repo::Repo::Type::SYSTEM}); } void ModuleDisableCommand::run() { diff --git a/dnf5/commands/module/module_enable.cpp b/dnf5/commands/module/module_enable.cpp index 4edd906009..b7f07b83be 100644 --- a/dnf5/commands/module/module_enable.cpp +++ b/dnf5/commands/module/module_enable.cpp @@ -50,8 +50,7 @@ void ModuleEnableCommand::set_argument_parser() { void ModuleEnableCommand::configure() { auto & context = get_context(); - context.set_load_system_repo(true); - context.set_load_available_repos(Context::LoadAvailableRepos::ENABLED); + context.set_load_enabled_repos({libdnf5::repo::Repo::Type::AVAILABLE, libdnf5::repo::Repo::Type::SYSTEM}); } void ModuleEnableCommand::run() { diff --git a/dnf5/commands/module/module_list.cpp b/dnf5/commands/module/module_list.cpp index 75972a73f0..77d9b49028 100644 --- a/dnf5/commands/module/module_list.cpp +++ b/dnf5/commands/module/module_list.cpp @@ -41,8 +41,7 @@ void ModuleListCommand::set_argument_parser() { void ModuleListCommand::configure() { auto & context = get_context(); - context.set_load_system_repo(true); - context.set_load_available_repos(Context::LoadAvailableRepos::ENABLED); + context.set_load_enabled_repos({libdnf5::repo::Repo::Type::AVAILABLE, libdnf5::repo::Repo::Type::SYSTEM}); } void ModuleListCommand::run() { diff --git a/dnf5/commands/module/module_reset.cpp b/dnf5/commands/module/module_reset.cpp index 4b5ee0b226..37cb1bf4df 100644 --- a/dnf5/commands/module/module_reset.cpp +++ b/dnf5/commands/module/module_reset.cpp @@ -50,8 +50,7 @@ void ModuleResetCommand::set_argument_parser() { void ModuleResetCommand::configure() { auto & context = get_context(); - context.set_load_system_repo(true); - context.set_load_available_repos(Context::LoadAvailableRepos::ENABLED); + context.set_load_enabled_repos({libdnf5::repo::Repo::Type::AVAILABLE, libdnf5::repo::Repo::Type::SYSTEM}); } void ModuleResetCommand::run() { diff --git a/dnf5/commands/provides/provides.cpp b/dnf5/commands/provides/provides.cpp index 5a055afeee..9048983630 100644 --- a/dnf5/commands/provides/provides.cpp +++ b/dnf5/commands/provides/provides.cpp @@ -61,10 +61,9 @@ void ProvidesCommand::set_argument_parser() { void ProvidesCommand::configure() { auto & context = get_context(); - context.set_load_system_repo(true); context.base.get_config().get_optional_metadata_types_option().add_item( libdnf5::Option::Priority::RUNTIME, libdnf5::METADATA_TYPE_FILELISTS); - context.set_load_available_repos(Context::LoadAvailableRepos::ENABLED); + context.set_load_enabled_repos({libdnf5::repo::Repo::Type::AVAILABLE, libdnf5::repo::Repo::Type::SYSTEM}); } std::pair ProvidesCommand::filter_spec( diff --git a/dnf5/commands/reinstall/reinstall.cpp b/dnf5/commands/reinstall/reinstall.cpp index 84b0c79453..dcc49512d7 100644 --- a/dnf5/commands/reinstall/reinstall.cpp +++ b/dnf5/commands/reinstall/reinstall.cpp @@ -60,8 +60,7 @@ void ReinstallCommand::set_argument_parser() { void ReinstallCommand::configure() { auto & context = get_context(); - context.set_load_system_repo(true); - context.set_load_available_repos(Context::LoadAvailableRepos::ENABLED); + context.set_load_enabled_repos({libdnf5::repo::Repo::Type::AVAILABLE, libdnf5::repo::Repo::Type::SYSTEM}); } void ReinstallCommand::run() { diff --git a/dnf5/commands/remove/remove.cpp b/dnf5/commands/remove/remove.cpp index 078e6457de..7f9e76a90a 100644 --- a/dnf5/commands/remove/remove.cpp +++ b/dnf5/commands/remove/remove.cpp @@ -59,8 +59,7 @@ void RemoveCommand::set_argument_parser() { void RemoveCommand::configure() { auto & context = get_context(); - context.set_load_system_repo(true); - context.set_load_available_repos(Context::LoadAvailableRepos::NONE); + context.set_load_enabled_repos({libdnf5::repo::Repo::Type::SYSTEM}); } void RemoveCommand::run() { diff --git a/dnf5/commands/repo/repo_info.cpp b/dnf5/commands/repo/repo_info.cpp index b2cd3a3474..c300ae187e 100644 --- a/dnf5/commands/repo/repo_info.cpp +++ b/dnf5/commands/repo/repo_info.cpp @@ -96,7 +96,7 @@ class RepoInfoWrapper : public libdnf5::cli::output::IRepoInfo { void RepoInfoCommand::configure() { auto & context = get_context(); - context.set_load_available_repos(Context::LoadAvailableRepos::ENABLED); + context.set_load_enabled_repos({libdnf5::repo::Repo::Type::AVAILABLE}); } void RepoInfoCommand::print(const libdnf5::repo::RepoQuery & query, [[maybe_unused]] bool with_status) { diff --git a/dnf5/commands/repoquery/repoquery.cpp b/dnf5/commands/repoquery/repoquery.cpp index 6173f76855..821d86531f 100644 --- a/dnf5/commands/repoquery/repoquery.cpp +++ b/dnf5/commands/repoquery/repoquery.cpp @@ -458,10 +458,13 @@ void RepoqueryCommand::configure() { auto & context = get_context(); context.update_repo_metadata_from_specs(pkg_specs); - system_repo_needed = installed_option->get_value() || userinstalled_option->get_value() || - duplicates->get_value() || leaves_option->get_value() || unneeded->get_value() || - extras->get_value() || upgrades->get_value() || installonly->get_value(); - context.set_load_system_repo(system_repo_needed); + std::vector which_repos_to_load; + bool system_repo_needed = installed_option->get_value() || userinstalled_option->get_value() || + duplicates->get_value() || leaves_option->get_value() || unneeded->get_value() || + extras->get_value() || upgrades->get_value() || installonly->get_value(); + if (system_repo_needed) { + which_repos_to_load.push_back(libdnf5::repo::Repo::Type::SYSTEM); + } context.update_repo_metadata_from_advisory_options( advisory_name->get_value(), advisory_security->get_value(), @@ -471,12 +474,14 @@ void RepoqueryCommand::configure() { advisory_severity->get_value(), advisory_bz->get_value(), advisory_cve->get_value()); - context.set_load_available_repos( - // available_option is on by default, to check if user specified it we check priority - available_option->get_priority() >= libdnf5::Option::Priority::COMMANDLINE || !system_repo_needed || - extras->get_value() || upgrades->get_value() || !providers_of_option->get_value().empty() - ? Context::LoadAvailableRepos::ENABLED - : Context::LoadAvailableRepos::NONE); + + // available_option is on by default, to check if user specified it we check priority + if (available_option->get_priority() >= libdnf5::Option::Priority::COMMANDLINE || !system_repo_needed || + extras->get_value() || upgrades->get_value() || !providers_of_option->get_value().empty()) { + which_repos_to_load.push_back(libdnf5::repo::Repo::Type::AVAILABLE); + } + + context.set_load_enabled_repos(which_repos_to_load); if (srpm->get_value()) { context.base.get_repo_sack()->enable_source_repos(); @@ -524,7 +529,7 @@ void RepoqueryCommand::configure() { void RepoqueryCommand::load_additional_packages() { auto & ctx = get_context(); - if (ctx.get_load_available_repos() != Context::LoadAvailableRepos::NONE) { + if (!ctx.get_load_enabled_repos().empty()) { for (auto & [path, package] : ctx.base.get_repo_sack()->add_cmdline_packages(pkg_specs)) { cmdline_packages.push_back(std::move(package)); } diff --git a/dnf5/commands/repoquery/repoquery.hpp b/dnf5/commands/repoquery/repoquery.hpp index 3872d8c62e..c00cc342da 100644 --- a/dnf5/commands/repoquery/repoquery.hpp +++ b/dnf5/commands/repoquery/repoquery.hpp @@ -43,8 +43,6 @@ class RepoqueryCommand : public Command { void run() override; private: - bool system_repo_needed = false; - libdnf5::OptionBool * available_option{nullptr}; libdnf5::OptionBool * installed_option{nullptr}; libdnf5::OptionBool * userinstalled_option{nullptr}; diff --git a/dnf5/commands/search/search.cpp b/dnf5/commands/search/search.cpp index 105ba67f57..01811a6d02 100644 --- a/dnf5/commands/search/search.cpp +++ b/dnf5/commands/search/search.cpp @@ -52,8 +52,7 @@ void SearchCommand::set_argument_parser() { void SearchCommand::configure() { auto & context = get_context(); - context.set_load_system_repo(true); - context.set_load_available_repos(Context::LoadAvailableRepos::ENABLED); + context.set_load_enabled_repos({libdnf5::repo::Repo::Type::AVAILABLE, libdnf5::repo::Repo::Type::SYSTEM}); } void SearchCommand::run() { diff --git a/dnf5/commands/swap/swap.cpp b/dnf5/commands/swap/swap.cpp index ec0eda7063..3f4a037690 100644 --- a/dnf5/commands/swap/swap.cpp +++ b/dnf5/commands/swap/swap.cpp @@ -72,8 +72,7 @@ void SwapCommand::set_argument_parser() { void SwapCommand::configure() { auto & context = get_context(); - context.set_load_system_repo(true); - context.set_load_available_repos(Context::LoadAvailableRepos::ENABLED); + context.set_load_enabled_repos({libdnf5::repo::Repo::Type::AVAILABLE, libdnf5::repo::Repo::Type::SYSTEM}); } void SwapCommand::run() { diff --git a/dnf5/commands/upgrade/upgrade.cpp b/dnf5/commands/upgrade/upgrade.cpp index ec696d1a22..5a726cb232 100644 --- a/dnf5/commands/upgrade/upgrade.cpp +++ b/dnf5/commands/upgrade/upgrade.cpp @@ -82,7 +82,6 @@ void UpgradeCommand::set_argument_parser() { void UpgradeCommand::configure() { auto & context = get_context(); context.update_repo_metadata_from_specs(pkg_specs); - context.set_load_system_repo(true); context.update_repo_metadata_from_advisory_options( advisory_name->get_value(), advisory_security->get_value(), @@ -92,7 +91,7 @@ void UpgradeCommand::configure() { advisory_severity->get_value(), advisory_bz->get_value(), advisory_cve->get_value()); - context.set_load_available_repos(Context::LoadAvailableRepos::ENABLED); + context.set_load_enabled_repos({libdnf5::repo::Repo::Type::AVAILABLE, libdnf5::repo::Repo::Type::SYSTEM}); } void UpgradeCommand::run() { diff --git a/dnf5/commands/versionlock/versionlock_add.cpp b/dnf5/commands/versionlock/versionlock_add.cpp index 1645e7ea17..b2967f547b 100644 --- a/dnf5/commands/versionlock/versionlock_add.cpp +++ b/dnf5/commands/versionlock/versionlock_add.cpp @@ -53,8 +53,7 @@ void VersionlockAddCommand::set_argument_parser() { void VersionlockAddCommand::configure() { auto & context = get_context(); - context.set_load_system_repo(true); - context.set_load_available_repos(Context::LoadAvailableRepos::ENABLED); + context.set_load_enabled_repos({libdnf5::repo::Repo::Type::AVAILABLE, libdnf5::repo::Repo::Type::SYSTEM}); } bool lock_version( diff --git a/dnf5/commands/versionlock/versionlock_exclude.cpp b/dnf5/commands/versionlock/versionlock_exclude.cpp index 2e605957b5..e355507fa2 100644 --- a/dnf5/commands/versionlock/versionlock_exclude.cpp +++ b/dnf5/commands/versionlock/versionlock_exclude.cpp @@ -53,7 +53,7 @@ void VersionlockExcludeCommand::set_argument_parser() { void VersionlockExcludeCommand::configure() { auto & context = get_context(); - context.set_load_available_repos(Context::LoadAvailableRepos::ENABLED); + context.set_load_enabled_repos({libdnf5::repo::Repo::Type::AVAILABLE}); } bool exclude_versions( diff --git a/dnf5/context.cpp b/dnf5/context.cpp index 8dd8db4255..31a47458cd 100644 --- a/dnf5/context.cpp +++ b/dnf5/context.cpp @@ -167,7 +167,11 @@ void Context::update_repo_metadata_from_advisory_options( } } -void Context::load_repos(bool load_system) { +void Context::load_repos(std::vector types) { + if (types.empty()) { + print_info("No repository types selected for loading."); + return; + } libdnf5::repo::RepoQuery repos(base); repos.filter_enabled(true); repos.filter_type(libdnf5::repo::Repo::Type::SYSTEM, libdnf5::sack::QueryCmp::NEQ); @@ -177,7 +181,7 @@ void Context::load_repos(bool load_system) { } print_info("Updating and loading repositories:"); - base.get_repo_sack()->update_and_load_enabled_repos(load_system); + base.get_repo_sack()->update_and_load_enabled_repos(types); if (auto download_callbacks = dynamic_cast(base.get_download_callbacks())) { download_callbacks->reset_progress_bar(); } @@ -561,17 +565,9 @@ std::vector match_specs( installed = available = false; } - if (installed) { - try { - base.get_repo_sack()->get_system_repo()->load(); - base.get_rpm_package_sack()->load_config_excludes_includes(); - } catch (...) { - // Ignores errors when completing installed packages, other completions may still work. - } - } - - if (available) { - try { + try { + std::vector types; + if (available) { // create rpm repositories according configuration files base.get_repo_sack()->create_repos_from_system_configuration(); base.get_config().get_optional_metadata_types_option().set( @@ -586,11 +582,15 @@ std::vector match_specs( repo->set_sync_strategy(libdnf5::repo::Repo::SyncStrategy::ONLY_CACHE); repo->get_config().get_skip_if_unavailable_option().set(libdnf5::Option::Priority::RUNTIME, true); } - - ctx.load_repos(false); - } catch (...) { - // Ignores errors when completing available packages, other completions may still work. + types.push_back(libdnf5::repo::Repo::Type::AVAILABLE); } + if (installed) { + types.push_back(libdnf5::repo::Repo::Type::SYSTEM); + } + + ctx.load_repos(types); + } catch (...) { + // Ignores errors when completing packages, other completions may still work. } std::set result_set; diff --git a/dnf5/include/dnf5/context.hpp b/dnf5/include/dnf5/context.hpp index 925042d02b..f75eb32e64 100644 --- a/dnf5/include/dnf5/context.hpp +++ b/dnf5/include/dnf5/context.hpp @@ -45,8 +45,6 @@ class Plugins; class Context : public libdnf5::cli::session::Session { public: - enum class LoadAvailableRepos { NONE, ENABLED, ALL }; - /// Constructs a new Context instance and sets the destination loggers. Context(std::vector> && loggers); @@ -70,7 +68,7 @@ class Context : public libdnf5::cli::session::Session { const std::vector & cves); /// Sets callbacks for repositories and loads them, updating metadata if necessary. - void load_repos(bool load_system); + void load_repos(std::vector types); libdnf5::Base base; std::vector> setopts; @@ -132,10 +130,9 @@ class Context : public libdnf5::cli::session::Session { libdnf5::base::Transaction * get_transaction() { return transaction.get(); } void set_load_system_repo(bool on) { load_system_repo = on; } - bool get_load_system_repo() const noexcept { return load_system_repo; } - void set_load_available_repos(LoadAvailableRepos which) { load_available_repos = which; } - LoadAvailableRepos get_load_available_repos() const noexcept { return load_available_repos; } + void set_load_enabled_repos(const std::vector & types) { load_enabled_repos = types; } + std::vector get_load_enabled_repos() const noexcept { return load_enabled_repos; } /// If quiet mode is not active, it will print `msg` to standard output. void print_info(std::string_view msg) const; @@ -161,7 +158,7 @@ class Context : public libdnf5::cli::session::Session { std::unique_ptr transaction; bool load_system_repo{false}; - LoadAvailableRepos load_available_repos{LoadAvailableRepos::NONE}; + std::vector load_enabled_repos; }; diff --git a/dnf5/main.cpp b/dnf5/main.cpp index c45d82ade4..d32ee9e0cf 100644 --- a/dnf5/main.cpp +++ b/dnf5/main.cpp @@ -1099,15 +1099,7 @@ int main(int argc, char * argv[]) try { dump_repository_configuration(context, repo_id_list); } - { - if (context.get_load_available_repos() != dnf5::Context::LoadAvailableRepos::NONE) { - context.load_repos(context.get_load_system_repo()); - } else if (context.get_load_system_repo()) { - repo_sack->get_system_repo()->load(); - // TODO(lukash) this is inconvenient, we should try to call it automatically at the right time in libdnf - context.base.get_rpm_package_sack()->load_config_excludes_includes(); - } - } + context.load_repos(context.get_load_enabled_repos()); command->load_additional_packages(); diff --git a/dnf5daemon-server/session.cpp b/dnf5daemon-server/session.cpp index c40733cf53..e8571416cc 100644 --- a/dnf5daemon-server/session.cpp +++ b/dnf5daemon-server/session.cpp @@ -207,6 +207,8 @@ bool Session::read_all_repos() { bool retval = true; + std::vector repos_to_load = {}; + bool load_available_repos = session_configuration_value("load_available_repos", true); bool load_system_repo = session_configuration_value("load_system_repo", true); std::vector optional_metadata_str = @@ -228,14 +230,19 @@ bool Session::read_all_repos() { repo->set_user_data(user_data.get()); repo->set_callbacks(std::make_unique(*this)); } + repos_to_load.push_back(libdnf5::repo::Repo::Type::AVAILABLE); + } + + if (load_system_repo) { + repos_to_load.push_back(libdnf5::repo::Repo::Type::SYSTEM); + } + if (!repos_to_load.empty()) { try { - base->get_repo_sack()->update_and_load_enabled_repos(load_system_repo); + base->get_repo_sack()->update_and_load_enabled_repos(repos_to_load); } catch (const std::runtime_error & ex) { retval = false; } - } else if (load_system_repo) { - base->get_repo_sack()->get_system_repo()->load(); } repositories_status = retval ? dnfdaemon::RepoStatus::READY : dnfdaemon::RepoStatus::ERROR;