Skip to content

Commit

Permalink
dnf5: Fix printing advisories for the running kernel
Browse files Browse the repository at this point in the history
The main problem was that --contains-pkgs values for default
(--available) behavior need to be applied after running kernel packages
are injected to packages query.
  • Loading branch information
m-blaha authored and kontura committed Jul 20, 2023
1 parent e8b9c30 commit bea2b76
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 27 deletions.
19 changes: 14 additions & 5 deletions dnf5/commands/advisory/advisory_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> & 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);
Expand All @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion dnf5/commands/advisory/advisory_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> & package_specs) override;
};

} // namespace dnf5
Expand Down
20 changes: 15 additions & 5 deletions dnf5/commands/advisory/advisory_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> & package_specs) {
std::vector<libdnf5::advisory::AdvisoryPackage> installed_pkgs;
std::vector<libdnf5::advisory::AdvisoryPackage> 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);
Expand All @@ -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()) {
Expand Down
4 changes: 3 additions & 1 deletion dnf5/commands/advisory/advisory_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> & package_specs) override;
};

} // namespace dnf5
Expand Down
9 changes: 1 addition & 8 deletions dnf5/commands/advisory/advisory_subcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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
4 changes: 3 additions & 1 deletion dnf5/commands/advisory/advisory_subcommand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> & package_specs) = 0;

void add_running_kernel_packages(libdnf5::Base & base, libdnf5::rpm::PackageQuery & package_query);

Expand Down
20 changes: 15 additions & 5 deletions dnf5/commands/advisory/advisory_summary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> & 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);
Expand All @@ -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");
}

Expand Down
4 changes: 3 additions & 1 deletion dnf5/commands/advisory/advisory_summary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> & package_specs) override;
};

} // namespace dnf5
Expand Down

0 comments on commit bea2b76

Please sign in to comment.