Skip to content

Commit

Permalink
needs-restarting: Fix filter_reboot_suggested
Browse files Browse the repository at this point in the history
filter_reboot_suggested was binary searching the results of
get_advisory_packages_sorted_by_name_arch_evr() assuming they were
sorted according to cmp_naevr, however that function actually returns
packages sorted by the libsolv ids of name, arch, and evr, not the
string representations of name, arch, and evr like cmp_naevr does.
  • Loading branch information
evan-goode committed Nov 6, 2023
1 parent b11d6c9 commit 48a643f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
10 changes: 9 additions & 1 deletion dnf5-plugins/needs_restarting_plugin/needs_restarting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,16 @@ void NeedsRestartingCommand::system_needs_restarting(Context & ctx) {
<< "Reboot should not be necessary." << std::endl;
} else {
std::cout << "Core libraries or services have been updated since boot-up:" << std::endl;
std::vector<std::string> need_reboot_names;
for (const auto & pkg : need_reboot) {
std::cout << " * " << pkg.get_name() << std::endl;
need_reboot_names.emplace_back(pkg.get_name());
}
std::sort(need_reboot_names.begin(), need_reboot_names.end());
need_reboot_names.erase(
std::unique(need_reboot_names.begin(), need_reboot_names.end()), need_reboot_names.end());

for (const auto & pkg_name : need_reboot_names) {
std::cout << " * " << pkg_name << std::endl;
}
std::cout << std::endl
<< "Reboot is required to fully utilize these updates." << std::endl
Expand Down
14 changes: 4 additions & 10 deletions libdnf5/rpm/package_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2852,27 +2852,21 @@ static const std::unordered_set<std::string> CORE_PACKAGE_NAMES = {

void PackageQuery::filter_reboot_suggested() {
auto & pool = get_rpm_pool(p_impl->base);
libdnf5::solv::SolvMap filter_result{pool.get_nsolvables()};
libdnf5::solv::SolvMap core_packages{pool.get_nsolvables()};

for (const auto & pkg : *this) {
if (CORE_PACKAGE_NAMES.contains(pkg.get_name())) {
filter_result.add_unsafe(pkg.get_id().id);
core_packages.add_unsafe(pkg.get_id().id);
}
}

libdnf5::advisory::AdvisoryQuery advisories{p_impl->base};
auto reboot_advisories = advisories.get_advisory_packages_sorted_by_name_arch_evr();
std::erase_if(reboot_advisories, [](const auto & pkg) { return !pkg.get_reboot_suggested(); });

const auto & cmp_naevr = libdnf5::rpm::cmp_naevr<const advisory::AdvisoryPackage &, const Package &>;
for (const auto & pkg : *this) {
auto lower = std::lower_bound(reboot_advisories.begin(), reboot_advisories.end(), pkg, cmp_naevr);
if (lower != reboot_advisories.end() && lower->get_nevra() == pkg.get_nevra()) {
filter_result.add_unsafe(pkg.get_id().id);
}
}
PQImpl::filter_sorted_advisory_pkgs(*this, reboot_advisories, libdnf5::sack::QueryCmp::EQ);

*p_impl &= filter_result;
*p_impl |= core_packages;
}

} // namespace libdnf5::rpm

0 comments on commit 48a643f

Please sign in to comment.