From eaf6a1937b494148df9de7675c4c916f2b39ed54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= Date: Thu, 12 Oct 2023 14:12:19 +0200 Subject: [PATCH] PackageQuery: add `filter_installonly` This allows it to be easily reused. --- dnf5/commands/repoquery/repoquery.cpp | 15 ++++++--------- include/libdnf5/rpm/package_query.hpp | 5 +++++ libdnf5/rpm/package_query.cpp | 5 +++++ libdnf5/rpm/transaction.cpp | 3 +-- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/dnf5/commands/repoquery/repoquery.cpp b/dnf5/commands/repoquery/repoquery.cpp index a8d33d543..609ba0555 100644 --- a/dnf5/commands/repoquery/repoquery.cpp +++ b/dnf5/commands/repoquery/repoquery.cpp @@ -492,13 +492,6 @@ static libdnf5::rpm::PackageSet resolve_nevras_to_packges( return resolved_nevras_set; } -static libdnf5::rpm::PackageQuery get_installonly_query(libdnf5::Base & base) { - auto & cfg_main = base.get_config(); - const auto & installonly_packages = cfg_main.get_installonlypkgs_option().get_value(); - libdnf5::rpm::PackageQuery installonly_query(base); - installonly_query.filter_provides(installonly_packages, libdnf5::sack::QueryCmp::GLOB); - return installonly_query; -} void RepoqueryCommand::run() { auto & ctx = get_context(); @@ -539,7 +532,9 @@ void RepoqueryCommand::run() { } if (duplicates->get_value()) { - result_query -= get_installonly_query(ctx.base); + libdnf5::rpm::PackageQuery installonly_query(ctx.base, flags, false); + installonly_query.filter_installonly(); + result_query -= installonly_query; result_query.filter_duplicates(); } @@ -548,7 +543,9 @@ void RepoqueryCommand::run() { } if (installonly->get_value()) { - result_query &= get_installonly_query(ctx.base); + libdnf5::rpm::PackageQuery installonly_query(ctx.base, flags, false); + installonly_query.filter_installonly(); + result_query &= installonly_query; } // APPLY FILTERS THAT REQUIRE BOTH INSTALLED AND AVAILABLE PACKAGES TO BE LOADED diff --git a/include/libdnf5/rpm/package_query.hpp b/include/libdnf5/rpm/package_query.hpp index 17bd246c2..560f32063 100644 --- a/include/libdnf5/rpm/package_query.hpp +++ b/include/libdnf5/rpm/package_query.hpp @@ -690,6 +690,11 @@ class PackageQuery : public PackageSet { /// @return Groups of one or more interdependent leaf packages. std::vector> filter_leaves_groups(); + /// Filter installonly packages. + /// + /// Filter packages that provide a capability that matches with any value in installonlypkgs configuration option. + void filter_installonly(); + private: std::vector> filter_leaves(bool return_grouped_leaves); diff --git a/libdnf5/rpm/package_query.cpp b/libdnf5/rpm/package_query.cpp index ae6626de8..e8cf7a9d1 100644 --- a/libdnf5/rpm/package_query.cpp +++ b/libdnf5/rpm/package_query.cpp @@ -2822,5 +2822,10 @@ void PackageQuery::filter_extras(const bool exact_evr) { } } +void PackageQuery::filter_installonly() { + auto & cfg_main = p_impl->base->get_config(); + const auto & installonly_packages = cfg_main.get_installonlypkgs_option().get_value(); + filter_provides(installonly_packages, libdnf5::sack::QueryCmp::GLOB); +} } // namespace libdnf5::rpm diff --git a/libdnf5/rpm/transaction.cpp b/libdnf5/rpm/transaction.cpp index 5cf6ff19f..d8eec7f7d 100644 --- a/libdnf5/rpm/transaction.cpp +++ b/libdnf5/rpm/transaction.cpp @@ -147,11 +147,10 @@ void Transaction::fill(const base::Transaction & transaction) { // Used to detect installation of a installonly package with lower version // that is currently installed. std::map installonly_versions; - const auto & installonlypkgs = base->get_config().get_installonlypkgs_option().get_value(); rpm::PackageQuery installonly_query(base); installonly_query.filter_installed(); installonly_query.filter_latest_evr(); - installonly_query.filter_provides(installonlypkgs, libdnf5::sack::QueryCmp::GLOB); + installonly_query.filter_installonly(); for (const auto & pkg : installonly_query) { installonly_versions.insert(std::make_pair(pkg.get_name(), pkg)); }