diff --git a/dnf5daemon-client/commands/clean/clean.cpp b/dnf5daemon-client/commands/clean/clean.cpp new file mode 100644 index 000000000..00cb86cd8 --- /dev/null +++ b/dnf5daemon-client/commands/clean/clean.cpp @@ -0,0 +1,92 @@ +/* +Copyright Contributors to the libdnf project. + +This file is part of libdnf: https://github.com/rpm-software-management/libdnf/ + +Libdnf is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +Libdnf is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with libdnf. If not, see . +*/ + +#include "clean.hpp" + +#include "commands/shared_options.hpp" +#include "context.hpp" +#include "exception.hpp" +#include "utils/auth.hpp" + +#include +#include +#include + +#include +#include + +namespace dnfdaemon::client { + +using namespace libdnf5::cli; + +void CleanCommand::set_parent_command() { + auto * arg_parser_parent_cmd = get_session().get_argument_parser().get_root_command(); + auto * arg_parser_this_cmd = get_argument_parser_command(); + arg_parser_parent_cmd->register_command(arg_parser_this_cmd); + arg_parser_parent_cmd->get_group("software_management_commands").register_argument(arg_parser_this_cmd); +} + +void CleanCommand::set_argument_parser() { + auto & parser = get_context().get_argument_parser(); + auto & cmd = *get_argument_parser_command(); + + cmd.set_description("Remove or expire cached data"); + + cache_types = parser.add_new_values(); + auto cache_types_arg = parser.add_new_positional_arg( + "cache_types", + 1, + parser.add_init_value(std::unique_ptr(new libdnf5::OptionString(nullptr))), + cache_types); + cache_types_arg->set_description("Cache type to clean up"); + cmd.register_positional_arg(cache_types_arg); +} + +void CleanCommand::run() { + auto & ctx = get_context(); + + if (!libdnf5::utils::am_i_root()) { + throw UnprivilegedUserError(); + } + + const std::string cache_type = dynamic_cast((*cache_types)[0].get())->get_value(); + bool success; + std::string error_msg; + ctx.session_proxy->callMethod("clean") + .onInterface(dnfdaemon::INTERFACE_BASE) + .withTimeout(static_cast(-1)) + .withArguments(cache_type) + .storeResultsTo(success, error_msg); + // make it compatible with `dnf5 clean metadata` which also cleans solv files + if (success && (cache_type == "metadata")) { + ctx.session_proxy->callMethod("clean") + .onInterface(dnfdaemon::INTERFACE_BASE) + .withTimeout(static_cast(-1)) + .withArguments("dbcache") + .storeResultsTo(success, error_msg); + } + + if (success) { + std::cout << "Cache successfully cleaned." << std::endl; + } else { + throw libdnf5::cli::CommandExitError(1, M_("Error cleaning the cache: {}"), error_msg); + } +} + +} // namespace dnfdaemon::client diff --git a/dnf5daemon-client/commands/clean/clean.hpp b/dnf5daemon-client/commands/clean/clean.hpp new file mode 100644 index 000000000..bdbe9dd0b --- /dev/null +++ b/dnf5daemon-client/commands/clean/clean.hpp @@ -0,0 +1,42 @@ +/* +Copyright Contributors to the libdnf project. + +This file is part of libdnf: https://github.com/rpm-software-management/libdnf/ + +Libdnf is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +Libdnf is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with libdnf. If not, see . +*/ + +#ifndef DNF5DAEMON_CLIENT_COMMANDS_CLEAN_CLEAN_HPP +#define DNF5DAEMON_CLIENT_COMMANDS_CLEAN_CLEAN_HPP + +#include "commands/command.hpp" + +#include + +namespace dnfdaemon::client { + +class CleanCommand : public TransactionCommand { +public: + explicit CleanCommand(Context & context) : TransactionCommand(context, "clean") {} + void set_parent_command() override; + void set_argument_parser() override; + void run() override; + +private: + std::vector> * cache_types{nullptr}; +}; + +} // namespace dnfdaemon::client + +#endif diff --git a/dnf5daemon-client/commands/repoquery/repoquery.cpp b/dnf5daemon-client/commands/repoquery/repoquery.cpp index 9573b2712..ec89e1779 100644 --- a/dnf5daemon-client/commands/repoquery/repoquery.cpp +++ b/dnf5daemon-client/commands/repoquery/repoquery.cpp @@ -208,13 +208,11 @@ void RepoqueryCommand::run() { return; } - std::string fd_id; ctx.session_proxy->callMethod("list_fd") .onInterface(dnfdaemon::INTERFACE_RPM) .withTimeout(static_cast(-1)) .withArguments(options) - .withArguments(sdbus::UnixFd{pipefd[1]}) - .withArguments(fd_id); + .withArguments(sdbus::UnixFd{pipefd[1]}); close(pipefd[1]); int in_fd = pipefd[0]; diff --git a/dnf5daemon-client/main.cpp b/dnf5daemon-client/main.cpp index c679f0acc..5c6638adf 100644 --- a/dnf5daemon-client/main.cpp +++ b/dnf5daemon-client/main.cpp @@ -18,6 +18,7 @@ along with libdnf. If not, see . */ #include "commands/advisory/advisory.hpp" +#include "commands/clean/clean.hpp" #include "commands/distro-sync/distro-sync.hpp" #include "commands/downgrade/downgrade.hpp" #include "commands/group/group.hpp" @@ -209,6 +210,7 @@ static void add_commands(Context & context) { context.add_and_initialize_command(std::make_unique(context, "repoinfo")); context.add_and_initialize_command(std::make_unique(context)); + context.add_and_initialize_command(std::make_unique(context)); } } // namespace dnfdaemon::client diff --git a/dnf5daemon-server/dbus/interfaces/org.rpm.dnf.v0.Base.xml b/dnf5daemon-server/dbus/interfaces/org.rpm.dnf.v0.Base.xml index 0a8f246d8..d79fe2fa6 100644 --- a/dnf5daemon-server/dbus/interfaces/org.rpm.dnf.v0.Base.xml +++ b/dnf5daemon-server/dbus/interfaces/org.rpm.dnf.v0.Base.xml @@ -35,6 +35,21 @@ along with libdnf. If not, see . + + + + + + +