diff --git a/dnf5/commands/advisory/advisory_info.cpp b/dnf5/commands/advisory/advisory_info.cpp index 223f3190a..f0887ba75 100644 --- a/dnf5/commands/advisory/advisory_info.cpp +++ b/dnf5/commands/advisory/advisory_info.cpp @@ -29,7 +29,11 @@ namespace dnf5 { using namespace libdnf5::cli; void AdvisoryInfoCommand::process_and_print_queries( - Context & ctx, libdnf5::advisory::AdvisoryQuery & advisories, libdnf5::rpm::PackageQuery & packages) { + Context & ctx, libdnf5::advisory::AdvisoryQuery & advisories, const std::vector & package_specs) { + libdnf5::rpm::PackageQuery packages(ctx.base); + if (package_specs.size() > 0) { + packages.filter_name(package_specs, libdnf5::sack::QueryCmp::IGLOB); + } if (all->get_value()) { packages.filter_installed(); advisories.filter_packages(packages, libdnf5::sack::QueryCmp::LTE); @@ -43,12 +47,17 @@ void AdvisoryInfoCommand::process_and_print_queries( packages.filter_upgradable(); advisories.filter_packages(packages, libdnf5::sack::QueryCmp::GT); } else { // available is the default - packages.filter_installed(); - packages.filter_latest_evr(); + libdnf5::rpm::PackageQuery installed_packages(ctx.base); + installed_packages.filter_installed(); + installed_packages.filter_latest_evr(); - add_running_kernel_packages(ctx.base, packages); + add_running_kernel_packages(ctx.base, installed_packages); - advisories.filter_packages(packages, libdnf5::sack::QueryCmp::GT); + if (package_specs.size() > 0) { + installed_packages.filter_name(package_specs, libdnf5::sack::QueryCmp::IGLOB); + } + + advisories.filter_packages(installed_packages, libdnf5::sack::QueryCmp::GT); } for (auto advisory : advisories) { diff --git a/dnf5/commands/advisory/advisory_info.hpp b/dnf5/commands/advisory/advisory_info.hpp index eadf13b28..a4e9e9f5e 100644 --- a/dnf5/commands/advisory/advisory_info.hpp +++ b/dnf5/commands/advisory/advisory_info.hpp @@ -35,7 +35,9 @@ class AdvisoryInfoCommand : public AdvisorySubCommand { protected: void process_and_print_queries( - Context & ctx, libdnf5::advisory::AdvisoryQuery & advisories, libdnf5::rpm::PackageQuery & packages) override; + Context & ctx, + libdnf5::advisory::AdvisoryQuery & advisories, + const std::vector & package_specs) override; }; } // namespace dnf5 diff --git a/dnf5/commands/advisory/advisory_list.cpp b/dnf5/commands/advisory/advisory_list.cpp index 13cf84b70..4bf458a8f 100644 --- a/dnf5/commands/advisory/advisory_list.cpp +++ b/dnf5/commands/advisory/advisory_list.cpp @@ -28,10 +28,15 @@ namespace dnf5 { using namespace libdnf5::cli; void AdvisoryListCommand::process_and_print_queries( - Context & ctx, libdnf5::advisory::AdvisoryQuery & advisories, libdnf5::rpm::PackageQuery & packages) { + Context & ctx, libdnf5::advisory::AdvisoryQuery & advisories, const std::vector & package_specs) { std::vector installed_pkgs; std::vector not_installed_pkgs; + libdnf5::rpm::PackageQuery packages(ctx.base); + if (package_specs.size() > 0) { + packages.filter_name(package_specs, libdnf5::sack::QueryCmp::IGLOB); + } + if (all->get_value()) { packages.filter_installed(); installed_pkgs = advisories.get_advisory_packages_sorted(packages, libdnf5::sack::QueryCmp::LTE); @@ -45,12 +50,17 @@ void AdvisoryListCommand::process_and_print_queries( packages.filter_upgradable(); not_installed_pkgs = advisories.get_advisory_packages_sorted(packages, libdnf5::sack::QueryCmp::GT); } else { // available is the default - packages.filter_installed(); - packages.filter_latest_evr(); + libdnf5::rpm::PackageQuery installed_packages(ctx.base); + installed_packages.filter_installed(); + installed_packages.filter_latest_evr(); - add_running_kernel_packages(ctx.base, packages); + add_running_kernel_packages(ctx.base, installed_packages); - not_installed_pkgs = advisories.get_advisory_packages_sorted(packages, libdnf5::sack::QueryCmp::GT); + if (package_specs.size() > 0) { + installed_packages.filter_name(package_specs, libdnf5::sack::QueryCmp::IGLOB); + } + + not_installed_pkgs = advisories.get_advisory_packages_sorted(installed_packages, libdnf5::sack::QueryCmp::GT); } if (with_bz->get_value()) { diff --git a/dnf5/commands/advisory/advisory_list.hpp b/dnf5/commands/advisory/advisory_list.hpp index 3864dced3..20733cac3 100644 --- a/dnf5/commands/advisory/advisory_list.hpp +++ b/dnf5/commands/advisory/advisory_list.hpp @@ -35,7 +35,9 @@ class AdvisoryListCommand : public AdvisorySubCommand { protected: void process_and_print_queries( - Context & ctx, libdnf5::advisory::AdvisoryQuery & advisories, libdnf5::rpm::PackageQuery & packages) override; + Context & ctx, + libdnf5::advisory::AdvisoryQuery & advisories, + const std::vector & package_specs) override; }; } // namespace dnf5 diff --git a/dnf5/commands/advisory/advisory_subcommand.cpp b/dnf5/commands/advisory/advisory_subcommand.cpp index e7b1aea60..0d3107648 100644 --- a/dnf5/commands/advisory/advisory_subcommand.cpp +++ b/dnf5/commands/advisory/advisory_subcommand.cpp @@ -81,13 +81,6 @@ void AdvisorySubCommand::configure() { void AdvisorySubCommand::run() { auto & ctx = get_context(); - libdnf5::rpm::PackageQuery package_query(ctx.base); - auto package_specs_strs = contains_pkgs->get_value(); - // Filter packages by name patterns if given - if (package_specs_strs.size() > 0) { - package_query.filter_name(package_specs_strs, libdnf5::sack::QueryCmp::IGLOB); - } - auto advisories_opt = advisory_query_from_cli_input( ctx.base, advisory_specs->get_value(), @@ -108,7 +101,7 @@ void AdvisorySubCommand::run() { advisories.filter_reference("*", {"cve"}, libdnf5::sack::QueryCmp::IGLOB); } - process_and_print_queries(ctx, advisories, package_query); + process_and_print_queries(ctx, advisories, contains_pkgs->get_value()); } } // namespace dnf5 diff --git a/dnf5/commands/advisory/advisory_subcommand.hpp b/dnf5/commands/advisory/advisory_subcommand.hpp index 756ef4437..2559950b2 100644 --- a/dnf5/commands/advisory/advisory_subcommand.hpp +++ b/dnf5/commands/advisory/advisory_subcommand.hpp @@ -38,7 +38,9 @@ class AdvisorySubCommand : public Command { protected: virtual void process_and_print_queries( - Context & ctx, libdnf5::advisory::AdvisoryQuery & advisories, libdnf5::rpm::PackageQuery & packages) = 0; + Context & ctx, + libdnf5::advisory::AdvisoryQuery & advisories, + const std::vector & package_specs) = 0; void add_running_kernel_packages(libdnf5::Base & base, libdnf5::rpm::PackageQuery & package_query); diff --git a/dnf5/commands/advisory/advisory_summary.cpp b/dnf5/commands/advisory/advisory_summary.cpp index baf50dbb3..abf4fe349 100644 --- a/dnf5/commands/advisory/advisory_summary.cpp +++ b/dnf5/commands/advisory/advisory_summary.cpp @@ -27,9 +27,14 @@ namespace dnf5 { using namespace libdnf5::cli; void AdvisorySummaryCommand::process_and_print_queries( - Context & ctx, libdnf5::advisory::AdvisoryQuery & advisories, libdnf5::rpm::PackageQuery & packages) { + Context & ctx, libdnf5::advisory::AdvisoryQuery & advisories, const std::vector & package_specs) { std::string mode; + libdnf5::rpm::PackageQuery packages(ctx.base); + if (package_specs.size() > 0) { + packages.filter_name(package_specs, libdnf5::sack::QueryCmp::IGLOB); + } + if (all->get_value()) { packages.filter_installed(); advisories.filter_packages(packages, libdnf5::sack::QueryCmp::LTE); @@ -46,12 +51,17 @@ void AdvisorySummaryCommand::process_and_print_queries( advisories.filter_packages(packages, libdnf5::sack::QueryCmp::GT); mode = _("Updates"); } else { // available is the default - packages.filter_installed(); - packages.filter_latest_evr(); + libdnf5::rpm::PackageQuery installed_packages(ctx.base); + installed_packages.filter_installed(); + installed_packages.filter_latest_evr(); - add_running_kernel_packages(ctx.base, packages); + add_running_kernel_packages(ctx.base, installed_packages); - advisories.filter_packages(packages, libdnf5::sack::QueryCmp::GT); + if (package_specs.size() > 0) { + installed_packages.filter_name(package_specs, libdnf5::sack::QueryCmp::IGLOB); + } + + advisories.filter_packages(installed_packages, libdnf5::sack::QueryCmp::GT); mode = _("Available"); } diff --git a/dnf5/commands/advisory/advisory_summary.hpp b/dnf5/commands/advisory/advisory_summary.hpp index a6bd1951f..73d3dfab4 100644 --- a/dnf5/commands/advisory/advisory_summary.hpp +++ b/dnf5/commands/advisory/advisory_summary.hpp @@ -35,7 +35,9 @@ class AdvisorySummaryCommand : public AdvisorySubCommand { protected: void process_and_print_queries( - Context & ctx, libdnf5::advisory::AdvisoryQuery & advisories, libdnf5::rpm::PackageQuery & packages) override; + Context & ctx, + libdnf5::advisory::AdvisoryQuery & advisories, + const std::vector & package_specs) override; }; } // namespace dnf5