Skip to content

Commit

Permalink
transaction: Add is_reboot_suggested
Browse files Browse the repository at this point in the history
Reboot is suggested for a transaction if any of the involved packages is
EITHER (1) part of a hardcoded set of "core" packages (including kernel
and systemd) OR (2) has an associated advisory with
reboot_suggested=True.

For rpm-software-management#587
  • Loading branch information
evan-goode committed Aug 31, 2023
1 parent da05ceb commit 05eac07
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/libdnf5/base/transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ class Transaction {
/// Retrieve a list of the problems that occurred during `check_gpg_signatures` procedure.
std::vector<std::string> get_gpg_signature_problems() const noexcept;

bool is_reboot_suggested();

private:
friend class TransactionEnvironment;
friend class TransactionGroup;
Expand Down
32 changes: 32 additions & 0 deletions libdnf5/base/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ std::vector<TransactionModule> & Transaction::get_transaction_modules() const {
return p_impl->modules;
}

bool Transaction::is_reboot_suggested() {
return p_impl->is_reboot_suggested();
}

GoalProblem Transaction::Impl::report_not_found(
GoalAction action,
const std::string & pkg_spec,
Expand Down Expand Up @@ -1022,4 +1026,32 @@ bool Transaction::Impl::check_gpg_signatures() {
return result;
}

static const std::unordered_set<std::string> CORE_PACKAGE_NAMES = {
"kernel",
"kernel-rt",
"kernel-core",
"glibc",
"linux-firmware",
"systemd",
"dbus",
"dbus-broker",
"dbus-daemon",
};

bool Transaction::Impl::is_reboot_suggested() {
libdnf5::advisory::AdvisoryQuery advisories{base};

libdnf5::rpm::PackageSet package_set{base};
for (const auto & trans_pkg : packages) {
if (CORE_PACKAGE_NAMES.contains(trans_pkg.get_package().get_name())) {
return true;
}
package_set.add(trans_pkg.get_package());
}
const auto & advisory_packages = advisories.get_advisory_packages_sorted(package_set, libdnf5::sack::QueryCmp::EQ);

return std::ranges::any_of(
advisory_packages, [](const auto & advisory_package) { return advisory_package.get_reboot_suggested(); });
}

} // namespace libdnf5::base
2 changes: 2 additions & 0 deletions libdnf5/base/transaction_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ class Transaction::Impl {

bool check_gpg_signatures();
ImportRepoKeysResult import_repo_keys(libdnf5::repo::Repo & repo);

bool is_reboot_suggested();
};


Expand Down

0 comments on commit 05eac07

Please sign in to comment.