From 9c2e21505876cb2fc9b0bfab650232818d112fe4 Mon Sep 17 00:00:00 2001 From: Marek Blaha Date: Tue, 9 Jul 2024 14:09:58 +0200 Subject: [PATCH] dnfdaemon: Replace check_pending() with get_status() Replace check_pending() method of the Offline interface with richer get_status() method. The new method returns two values: - boolean whether there is a dnf5 offline transaction scheduled for the next reboot - a string->variant dictionary with the status of the dnf5 offline transaction --- .../interfaces/org.rpm.dnf.v0.Offline.xml | 8 ++++-- .../services/offline/offline.cpp | 28 +++++++++++++++---- .../services/offline/offline.hpp | 2 +- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/dnf5daemon-server/dbus/interfaces/org.rpm.dnf.v0.Offline.xml b/dnf5daemon-server/dbus/interfaces/org.rpm.dnf.v0.Offline.xml index d6986e866..083b5b17c 100644 --- a/dnf5daemon-server/dbus/interfaces/org.rpm.dnf.v0.Offline.xml +++ b/dnf5daemon-server/dbus/interfaces/org.rpm.dnf.v0.Offline.xml @@ -26,13 +26,15 @@ along with libdnf. If not, see . --> - + + diff --git a/dnf5daemon-server/services/offline/offline.cpp b/dnf5daemon-server/services/offline/offline.cpp index b3848ac91..27e6d7931 100644 --- a/dnf5daemon-server/services/offline/offline.cpp +++ b/dnf5daemon-server/services/offline/offline.cpp @@ -64,13 +64,13 @@ void Offline::dbus_register() { }); dbus_object->registerMethod( dnfdaemon::INTERFACE_OFFLINE, - "check_pending", + "get_status", {}, {}, - "b", - {"pending"}, + "ba{sv}", + {"is_pending", "transaction_status"}, [this](sdbus::MethodCall call) -> void { - session.get_threads_manager().handle_method(*this, &Offline::check_pending, call, session.session_locale); + session.get_threads_manager().handle_method(*this, &Offline::get_status, call, session.session_locale); }); dbus_object->registerMethod( dnfdaemon::INTERFACE_OFFLINE, @@ -95,9 +95,27 @@ void Offline::dbus_register() { }); } -sdbus::MethodReply Offline::check_pending(sdbus::MethodCall & call) { +sdbus::MethodReply Offline::get_status(sdbus::MethodCall & call) { + dnfdaemon::KeyValueMap transaction_state; + + const std::filesystem::path state_path{get_datadir() / libdnf5::offline::TRANSACTION_STATE_FILENAME}; + // try load the offline transaction state + libdnf5::offline::OfflineTransactionState state{state_path}; + if (!state.get_read_exception()) { + const auto & state_data = state.get_data(); + transaction_state["status"] = state_data.get_status(); + transaction_state["cachedir"] = state_data.get_cachedir(); + transaction_state["target_releasever"] = state_data.get_target_releasever(); + transaction_state["system_releasever"] = state_data.get_system_releasever(); + transaction_state["verb"] = state_data.get_verb(); + transaction_state["cmd_line"] = state_data.get_cmd_line(); + transaction_state["poweroff_after"] = state_data.get_poweroff_after(); + transaction_state["module_platform_id"] = state_data.get_module_platform_id(); + } + auto reply = call.createReply(); reply << (offline_transaction_scheduled() == Scheduled::SCHEDULED); + reply << transaction_state; return reply; } diff --git a/dnf5daemon-server/services/offline/offline.hpp b/dnf5daemon-server/services/offline/offline.hpp index e9f444932..d25d081f7 100644 --- a/dnf5daemon-server/services/offline/offline.hpp +++ b/dnf5daemon-server/services/offline/offline.hpp @@ -35,8 +35,8 @@ class Offline : public IDbusSessionService { private: sdbus::MethodReply cancel(sdbus::MethodCall & call); - sdbus::MethodReply check_pending(sdbus::MethodCall & call); sdbus::MethodReply clean(sdbus::MethodCall & call); + sdbus::MethodReply get_status(sdbus::MethodCall & call); sdbus::MethodReply set_finish_action(sdbus::MethodCall & call); enum class Scheduled { NOT_SCHEDULED, ANOTHER_TOOL, SCHEDULED };