From 677b8b5b31b950b231ad452a8855181f2e8706fa Mon Sep 17 00:00:00 2001 From: Marek Blaha Date: Wed, 12 Jun 2024 18:45:15 +0200 Subject: [PATCH] dnfdaemon: Add new API for offline transactions - Goal::offline_transaction_pending - check whether there is an offline update scheduled for the next reboot - Goal:: offline_transaction_clean - cancel the scheduled offline update --- .../dbus/interfaces/org.rpm.dnf.v0.Goal.xml | 30 +++++++++++ dnf5daemon-server/services/goal/goal.cpp | 52 +++++++++++++++++++ dnf5daemon-server/services/goal/goal.hpp | 2 + 3 files changed, 84 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 56014b7bb..8fe414846 100644 --- a/dnf5daemon-server/dbus/interfaces/org.rpm.dnf.v0.Goal.xml +++ b/dnf5daemon-server/dbus/interfaces/org.rpm.dnf.v0.Goal.xml @@ -94,6 +94,36 @@ along with libdnf. If not, see . + + + + + + + + + + + + + diff --git a/dnf5daemon-server/services/goal/goal.cpp b/dnf5daemon-server/services/goal/goal.cpp index dc6927cc2..7c226dd3c 100644 --- a/dnf5daemon-server/services/goal/goal.cpp +++ b/dnf5daemon-server/services/goal/goal.cpp @@ -105,6 +105,28 @@ void Goal::dbus_register() { [this](sdbus::MethodCall call) -> void { session.get_threads_manager().handle_method(*this, &Goal::do_transaction, call, session.session_locale); }); + dbus_object->registerMethod( + dnfdaemon::INTERFACE_GOAL, + "offline_transaction_pending", + {}, + {}, + "b", + {"pending"}, + [this](sdbus::MethodCall call) -> void { + session.get_threads_manager().handle_method( + *this, &Goal::offline_transaction_pending, call, session.session_locale); + }); + dbus_object->registerMethod( + dnfdaemon::INTERFACE_GOAL, + "offline_transaction_clean", + "a{sv}", + {"options"}, + "b", + {"transaction_cleaned"}, + [this](sdbus::MethodCall call) -> void { + session.get_threads_manager().handle_method( + *this, &Goal::offline_transaction_clean, call, session.session_locale); + }); } sdbus::MethodReply Goal::resolve(sdbus::MethodCall & call) { @@ -307,3 +329,33 @@ sdbus::MethodReply Goal::do_transaction(sdbus::MethodCall & call) { auto reply = call.createReply(); return reply; } + +sdbus::MethodReply Goal::offline_transaction_pending(sdbus::MethodCall & call) { + // check the presence of the magic symlink + auto reply = call.createReply(); + std::error_code ec; + reply << std::filesystem::exists(libdnf5::offline::MAGIC_SYMLINK, ec); + return reply; +} + +sdbus::MethodReply Goal::offline_transaction_clean(sdbus::MethodCall & call) { + dnfdaemon::KeyValueMap options; + call >> options; + bool clean_datadir = dnfdaemon::key_value_map_get(options, "clean_datadir", true); + bool cleaned = true; + std::error_code ec; + if (!std::filesystem::remove(libdnf5::offline::MAGIC_SYMLINK, ec) && ec) { + cleaned = false; + } + if (clean_datadir) { + auto base = session.get_base(); + const auto & installroot = base->get_config().get_installroot_option().get_value(); + std::filesystem::path datadir = installroot / libdnf5::offline::DEFAULT_DATADIR.relative_path(); + for (const auto & entry : std::filesystem::directory_iterator(datadir)) { + std::filesystem::remove_all(entry.path(), ec); + } + } + auto reply = call.createReply(); + reply << cleaned; + return reply; +} diff --git a/dnf5daemon-server/services/goal/goal.hpp b/dnf5daemon-server/services/goal/goal.hpp index f9f66c1fe..d141968b3 100644 --- a/dnf5daemon-server/services/goal/goal.hpp +++ b/dnf5daemon-server/services/goal/goal.hpp @@ -36,6 +36,8 @@ class Goal : public IDbusSessionService { sdbus::MethodReply get_transaction_problems_string(sdbus::MethodCall & call); sdbus::MethodReply get_transaction_problems(sdbus::MethodCall & call); sdbus::MethodReply do_transaction(sdbus::MethodCall & call); + sdbus::MethodReply offline_transaction_pending(sdbus::MethodCall & call); + sdbus::MethodReply offline_transaction_clean(sdbus::MethodCall & call); }; #endif