Skip to content

Commit

Permalink
dnfdaemon-client: --offline option for transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
m-blaha committed Jun 7, 2024
1 parent 89f948b commit fbfa861
Show file tree
Hide file tree
Showing 16 changed files with 66 additions and 16 deletions.
3 changes: 2 additions & 1 deletion dnf5daemon-client/commands/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

namespace dnfdaemon::client {

void TransactionCommand::run_transaction() {
void TransactionCommand::run_transaction(bool offline) {
auto & ctx = get_context();
dnfdaemon::KeyValueMap options = {};

Expand Down Expand Up @@ -80,6 +80,7 @@ void TransactionCommand::run_transaction() {

// do the transaction
options.clear();
options["offline"] = offline;
ctx.session_proxy->callMethod("do_transaction")
.onInterface(dnfdaemon::INTERFACE_GOAL)
.withTimeout(static_cast<uint64_t>(-1))
Expand Down
2 changes: 1 addition & 1 deletion dnf5daemon-client/commands/command.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class DaemonCommand : public libdnf5::cli::session::Command {
class TransactionCommand : public DaemonCommand {
public:
explicit TransactionCommand(Context & context, const std::string & name) : DaemonCommand(context, name){};
void run_transaction();
void run_transaction(bool offline = false);
};


Expand Down
5 changes: 4 additions & 1 deletion dnf5daemon-client/commands/distro-sync/distro-sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ void DistroSyncCommand::set_argument_parser() {
auto specs_arg = pkg_specs_argument(parser, libdnf5::cli::ArgumentParser::PositionalArg::UNLIMITED, pkg_specs);
specs_arg->set_description("Patterns");
cmd.register_positional_arg(specs_arg);

auto offline_arg = create_offline_option(parser, &offline_option);
cmd.register_named_arg(offline_arg);
}

void DistroSyncCommand::run() {
Expand All @@ -65,7 +68,7 @@ void DistroSyncCommand::run() {
.withTimeout(static_cast<uint64_t>(-1))
.withArguments(pkg_specs, options);

run_transaction();
run_transaction(offline_option.get_value());
}

} // namespace dnfdaemon::client
3 changes: 2 additions & 1 deletion dnf5daemon-client/commands/distro-sync/distro-sync.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

#include "commands/command.hpp"

#include <libdnf5/conf/option.hpp>
#include <libdnf5/conf/option_bool.hpp>

namespace dnfdaemon::client {

Expand All @@ -35,6 +35,7 @@ class DistroSyncCommand : public TransactionCommand {

private:
std::vector<std::string> pkg_specs;
libdnf5::OptionBool offline_option{false};
};

} // namespace dnfdaemon::client
Expand Down
5 changes: 4 additions & 1 deletion dnf5daemon-client/commands/downgrade/downgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ void DowngradeCommand::set_argument_parser() {
auto specs_arg = pkg_specs_argument(parser, libdnf5::cli::ArgumentParser::PositionalArg::AT_LEAST_ONE, pkg_specs);
specs_arg->set_description("List of packages to downgrade");
cmd.register_positional_arg(specs_arg);

auto offline_arg = create_offline_option(parser, &offline_option);
cmd.register_named_arg(offline_arg);
}

void DowngradeCommand::run() {
Expand All @@ -65,7 +68,7 @@ void DowngradeCommand::run() {
.withTimeout(static_cast<uint64_t>(-1))
.withArguments(pkg_specs, options);

run_transaction();
run_transaction(offline_option.get_value());
}

} // namespace dnfdaemon::client
3 changes: 2 additions & 1 deletion dnf5daemon-client/commands/downgrade/downgrade.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

#include "commands/command.hpp"

#include <libdnf5/conf/option.hpp>
#include <libdnf5/conf/option_bool.hpp>

namespace dnfdaemon::client {

Expand All @@ -35,6 +35,7 @@ class DowngradeCommand : public TransactionCommand {

private:
std::vector<std::string> pkg_specs{};
libdnf5::OptionBool offline_option{false};
};

} // namespace dnfdaemon::client
Expand Down
5 changes: 4 additions & 1 deletion dnf5daemon-client/commands/install/install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ void InstallCommand::set_argument_parser() {
skip_unavailable->link_value(&skip_unavailable_option);
cmd.register_named_arg(skip_unavailable);

auto offline_arg = create_offline_option(parser, &offline_option);
cmd.register_named_arg(offline_arg);

auto specs_arg = pkg_specs_argument(parser, libdnf5::cli::ArgumentParser::PositionalArg::AT_LEAST_ONE, pkg_specs);
specs_arg->set_description("List of packages to install");
cmd.register_positional_arg(specs_arg);
Expand All @@ -88,7 +91,7 @@ void InstallCommand::run() {
.withTimeout(static_cast<uint64_t>(-1))
.withArguments(pkg_specs, options);

run_transaction();
run_transaction(offline_option.get_value());
}

} // namespace dnfdaemon::client
4 changes: 2 additions & 2 deletions dnf5daemon-client/commands/install/install.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

#include "commands/command.hpp"

#include <libdnf5/conf/option.hpp>
#include <libdnf5/conf/option_bool.hpp>

namespace dnfdaemon::client {
Expand All @@ -35,9 +34,10 @@ class InstallCommand : public TransactionCommand {
void run() override;

private:
std::vector<std::string> pkg_specs{};
libdnf5::OptionBool skip_broken_option{false};
libdnf5::OptionBool skip_unavailable_option{false};
std::vector<std::string> pkg_specs{};
libdnf5::OptionBool offline_option{false};
};

} // namespace dnfdaemon::client
Expand Down
5 changes: 4 additions & 1 deletion dnf5daemon-client/commands/reinstall/reinstall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ void ReinstallCommand::set_argument_parser() {
auto specs_arg = pkg_specs_argument(parser, libdnf5::cli::ArgumentParser::PositionalArg::AT_LEAST_ONE, pkg_specs);
specs_arg->set_description("List of packages to reinstall");
cmd.register_positional_arg(specs_arg);

auto offline_arg = create_offline_option(parser, &offline_option);
cmd.register_named_arg(offline_arg);
}

void ReinstallCommand::run() {
Expand All @@ -65,7 +68,7 @@ void ReinstallCommand::run() {
.withTimeout(static_cast<uint64_t>(-1))
.withArguments(pkg_specs, options);

run_transaction();
run_transaction(offline_option.get_value());
}

} // namespace dnfdaemon::client
3 changes: 2 additions & 1 deletion dnf5daemon-client/commands/reinstall/reinstall.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

#include "commands/command.hpp"

#include <libdnf5/conf/option.hpp>
#include <libdnf5/conf/option_bool.hpp>

namespace dnfdaemon::client {

Expand All @@ -35,6 +35,7 @@ class ReinstallCommand : public TransactionCommand {

private:
std::vector<std::string> pkg_specs{};
libdnf5::OptionBool offline_option{false};
};

} // namespace dnfdaemon::client
Expand Down
5 changes: 4 additions & 1 deletion dnf5daemon-client/commands/remove/remove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ void RemoveCommand::set_argument_parser() {
specs_arg->set_description("List of packages to remove");
cmd.register_positional_arg(specs_arg);

auto offline_arg = create_offline_option(parser, &offline_option);
cmd.register_named_arg(offline_arg);

// run remove command always with allow_erasing on
context.allow_erasing.set(libdnf5::Option::Priority::RUNTIME, true);
}
Expand All @@ -69,7 +72,7 @@ void RemoveCommand::run() {
.withTimeout(static_cast<uint64_t>(-1))
.withArguments(pkg_specs, options);

run_transaction();
run_transaction(offline_option.get_value());
}

} // namespace dnfdaemon::client
3 changes: 2 additions & 1 deletion dnf5daemon-client/commands/remove/remove.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

#include "commands/command.hpp"

#include <libdnf5/conf/option.hpp>
#include <libdnf5/conf/option_bool.hpp>

namespace dnfdaemon::client {

Expand All @@ -35,6 +35,7 @@ class RemoveCommand : public TransactionCommand {

private:
std::vector<std::string> pkg_specs{};
libdnf5::OptionBool offline_option{false};
};

} // namespace dnfdaemon::client
Expand Down
20 changes: 20 additions & 0 deletions dnf5daemon-client/commands/shared_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

#include "utils/url.hpp"

#include <libdnf5-cli/argument_parser.hpp>

#include <filesystem>

namespace {

static void normalize_paths(int specs_count, const char * const specs[], std::vector<std::string> & pkg_specs) {
const std::string_view ext(".rpm");
std::set<std::string_view> unique_items;
Expand All @@ -39,6 +43,10 @@ static void normalize_paths(int specs_count, const char * const specs[], std::ve
}
}

} // anonymous namespace

namespace dnfdaemon::client {

libdnf5::cli::ArgumentParser::PositionalArg * pkg_specs_argument(
libdnf5::cli::ArgumentParser & parser, int nargs, std::vector<std::string> & pkg_specs) {
auto specs = parser.add_new_positional_arg("pkg_specs", nargs, nullptr, nullptr);
Expand All @@ -49,3 +57,15 @@ libdnf5::cli::ArgumentParser::PositionalArg * pkg_specs_argument(
});
return specs;
}

libdnf5::cli::ArgumentParser::NamedArg * create_offline_option(
libdnf5::cli::ArgumentParser & parser, libdnf5::Option * value) {
auto offline = parser.add_new_named_arg("offline");
offline->set_long_name("offline");
offline->set_description("Store the transaction to be performed offline");
offline->set_const_value("true");
offline->link_value(value);
return offline;
}

} // namespace dnfdaemon::client
7 changes: 7 additions & 0 deletions dnf5daemon-client/commands/shared_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

#include <libdnf5-cli/argument_parser.hpp>

namespace dnfdaemon::client {

libdnf5::cli::ArgumentParser::PositionalArg * pkg_specs_argument(
libdnf5::cli::ArgumentParser & parser, int nargs, std::vector<std::string> & pkg_specs);

/// Create the `--offline` named arg bound to the given option
libdnf5::cli::ArgumentParser::NamedArg * create_offline_option(
libdnf5::cli::ArgumentParser & parser, libdnf5::Option * value);

} // namespace dnfdaemon::client
#endif
6 changes: 4 additions & 2 deletions dnf5daemon-client/commands/upgrade/upgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ void UpgradeCommand::set_argument_parser() {
auto specs_arg = pkg_specs_argument(parser, libdnf5::cli::ArgumentParser::PositionalArg::UNLIMITED, pkg_specs);
specs_arg->set_description("List of packages to upgrade");
cmd.register_positional_arg(specs_arg);

auto offline_arg = create_offline_option(parser, &offline_option);
cmd.register_named_arg(offline_arg);
}

void UpgradeCommand::run() {
Expand All @@ -59,13 +62,12 @@ void UpgradeCommand::run() {
}

dnfdaemon::KeyValueMap options = {};

ctx.session_proxy->callMethod("upgrade")
.onInterface(dnfdaemon::INTERFACE_RPM)
.withTimeout(static_cast<uint64_t>(-1))
.withArguments(pkg_specs, options);

run_transaction();
run_transaction(offline_option.get_value());
}

} // namespace dnfdaemon::client
3 changes: 2 additions & 1 deletion dnf5daemon-client/commands/upgrade/upgrade.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

#include "commands/command.hpp"

#include <libdnf5/conf/option.hpp>
#include <libdnf5/conf/option_bool.hpp>

namespace dnfdaemon::client {

Expand All @@ -35,6 +35,7 @@ class UpgradeCommand : public TransactionCommand {

private:
std::vector<std::string> pkg_specs{};
libdnf5::OptionBool offline_option{false};
};

} // namespace dnfdaemon::client
Expand Down

0 comments on commit fbfa861

Please sign in to comment.