Skip to content

Commit

Permalink
dnfdaemon: Add new API for offline transactions
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
m-blaha committed Jun 13, 2024
1 parent fbfa861 commit 677b8b5
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
30 changes: 30 additions & 0 deletions dnf5daemon-server/dbus/interfaces/org.rpm.dnf.v0.Goal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,36 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
<arg name="options" type="a{sv}" direction="in" />
</method>


<!--
offline_transaction_pending:
@pending: boolean, true if there is a pending offline transaction
Check whether there is an offline transaction configured for the next reboot (i.e. checks the /system-update symlink existence).
-->
<method name="offline_transaction_pending">
<arg name="pending" type="b" direction="out" />
</method>


<!--
offline_transaction_clean:
@options: an array of key/value pairs
@transaction_cleaned: boolean, returns `false` if there was an error during the transaction cleanup. Returns `true` if the offline transaction was successfully cleaned or if no offline transaction was configured.
Clean the offline transaction configured for the next reboot by removing the /system-update symlink (see systemd.offline-updates(7)).
Following @options are supported:
- clean_datadir: boolean, default true
If true, all stored offline transaction data, including downloaded packages, will be removed along with the system-update symlink.
Unknown options are ignored.
-->
<method name="do_transaction">
<arg name="options" type="a{sv}" direction="in" />
<arg name="transaction_cleaned" type="b" direction="out" />
</method>

</interface>

</node>
52 changes: 52 additions & 0 deletions dnf5daemon-server/services/goal/goal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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<bool>(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;
}
2 changes: 2 additions & 0 deletions dnf5daemon-server/services/goal/goal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 677b8b5

Please sign in to comment.