From 159e509dabe7f0f473888460a6951524a5475ec8 Mon Sep 17 00:00:00 2001 From: Marek Blaha Date: Thu, 5 Sep 2024 16:40:45 +0200 Subject: [PATCH 1/3] goal: Add missing members to reset() method The reset() method currently does not reset all Goal members. This patch adds those that are missing. --- libdnf5/base/goal.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libdnf5/base/goal.cpp b/libdnf5/base/goal.cpp index 5cda9b8d1..e79f8db38 100644 --- a/libdnf5/base/goal.cpp +++ b/libdnf5/base/goal.cpp @@ -3296,12 +3296,17 @@ void Goal::add_redo_transaction( void Goal::reset() { p_impl->module_specs.clear(); p_impl->rpm_specs.clear(); + p_impl->rpm_reason_change_specs.clear(); p_impl->rpm_ids.clear(); p_impl->group_specs.clear(); p_impl->rpm_filepaths.clear(); p_impl->resolved_group_specs.clear(); p_impl->resolved_environment_specs.clear(); + p_impl->group_specs.clear(); p_impl->rpm_goal = rpm::solv::GoalPrivate(p_impl->base); + p_impl->serialized_transaction.reset(); + p_impl->revert_transactions.reset(); + p_impl->redo_transaction.reset(); } BaseWeakPtr Goal::get_base() const { From c9c0848380d44ad51a2af610d10ff13c98e7ceb6 Mon Sep 17 00:00:00 2001 From: Marek Blaha Date: Thu, 5 Sep 2024 16:42:49 +0200 Subject: [PATCH 2/3] dnfdaemon: Add reset_goal() method The method resets the current goal and transaction, which is necessary for scenarios where the user wants to reuse the D-Bus session to resolve or execute multiple transactions. --- dnf5daemon-server/session.cpp | 5 +++++ dnf5daemon-server/session.hpp | 2 ++ 2 files changed, 7 insertions(+) diff --git a/dnf5daemon-server/session.cpp b/dnf5daemon-server/session.cpp index cd18f5685..7ecc01ec6 100644 --- a/dnf5daemon-server/session.cpp +++ b/dnf5daemon-server/session.cpp @@ -377,3 +377,8 @@ void Session::store_transaction_offline() { state.write(); } + +void Session::reset_goal() { + transaction.reset(nullptr); + goal.reset(); +} diff --git a/dnf5daemon-server/session.hpp b/dnf5daemon-server/session.hpp index defc2cf74..9d1637247 100644 --- a/dnf5daemon-server/session.hpp +++ b/dnf5daemon-server/session.hpp @@ -99,6 +99,8 @@ class Session { /// Setter for download cancel request flag. void set_cancel_download(CancelDownload value) { cancel_download.store(value); } + void reset_goal(); + private: sdbus::IConnection & connection; std::unique_ptr base; From 6dd2cb7b706299b5b355f3e84b1ffbe036c7bc29 Mon Sep 17 00:00:00 2001 From: Marek Blaha Date: Fri, 6 Sep 2024 09:15:03 +0200 Subject: [PATCH 3/3] dnfdaemon: D-Bus API to reset the goal With this patch the user can re-use the session to resolve multiple transactions without running them. The use case might be to check what dependencies would be installed with given package. --- .../dbus/interfaces/org.rpm.dnf.v0.Goal.xml | 7 +++++++ dnf5daemon-server/services/goal/goal.cpp | 10 ++++++++++ dnf5daemon-server/services/goal/goal.hpp | 1 + 3 files changed, 18 insertions(+) diff --git a/dnf5daemon-server/dbus/interfaces/org.rpm.dnf.v0.Goal.xml b/dnf5daemon-server/dbus/interfaces/org.rpm.dnf.v0.Goal.xml index ab142e21f..f1ba08953 100644 --- a/dnf5daemon-server/dbus/interfaces/org.rpm.dnf.v0.Goal.xml +++ b/dnf5daemon-server/dbus/interfaces/org.rpm.dnf.v0.Goal.xml @@ -106,6 +106,13 @@ along with libdnf. If not, see . + + + + diff --git a/dnf5daemon-server/services/goal/goal.cpp b/dnf5daemon-server/services/goal/goal.cpp index 0052441b8..3aa1c6a7d 100644 --- a/dnf5daemon-server/services/goal/goal.cpp +++ b/dnf5daemon-server/services/goal/goal.cpp @@ -114,6 +114,10 @@ void Goal::dbus_register() { [this](sdbus::MethodCall call) -> void { session.get_threads_manager().handle_method(*this, &Goal::cancel, call, session.session_locale); }); + dbus_object->registerMethod( + dnfdaemon::INTERFACE_GOAL, "reset", "", {}, "", {}, [this](sdbus::MethodCall call) -> void { + session.get_threads_manager().handle_method(*this, &Goal::reset, call, session.session_locale); + }); } sdbus::MethodReply Goal::resolve(sdbus::MethodCall & call) { @@ -346,3 +350,9 @@ sdbus::MethodReply Goal::cancel(sdbus::MethodCall & call) { reply << error_msg; return reply; } + +sdbus::MethodReply Goal::reset(sdbus::MethodCall & call) { + session.reset_goal(); + auto reply = call.createReply(); + return reply; +} diff --git a/dnf5daemon-server/services/goal/goal.hpp b/dnf5daemon-server/services/goal/goal.hpp index d19b6001e..bbf3d9086 100644 --- a/dnf5daemon-server/services/goal/goal.hpp +++ b/dnf5daemon-server/services/goal/goal.hpp @@ -37,6 +37,7 @@ class Goal : public IDbusSessionService { sdbus::MethodReply get_transaction_problems(sdbus::MethodCall & call); sdbus::MethodReply do_transaction(sdbus::MethodCall & call); sdbus::MethodReply cancel(sdbus::MethodCall & call); + sdbus::MethodReply reset(sdbus::MethodCall & call); }; #endif