From c2b3b166f5db3cbfd5674ffff85d390faf5a2d3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= Date: Tue, 17 Oct 2023 15:13:54 +0200 Subject: [PATCH] Enable history replay command It uses TransactionReplay. There is a new argument `--resolve` which determines if the loaded transaction is resolved again through Goal or not. --- dnf5/commands/history/history.cpp | 8 ++-- dnf5/commands/history/history_replay.cpp | 48 +++++++++++++++++++++++- dnf5/commands/history/history_replay.hpp | 15 +++++++- 3 files changed, 64 insertions(+), 7 deletions(-) diff --git a/dnf5/commands/history/history.cpp b/dnf5/commands/history/history.cpp index 304304c25..7a9fa2d73 100644 --- a/dnf5/commands/history/history.cpp +++ b/dnf5/commands/history/history.cpp @@ -54,14 +54,14 @@ void HistoryCommand::register_subcommands() { register_subcommand(std::make_unique(get_context()), query_commands_group); // software management commands - // auto * software_management_commands_group = parser.add_new_group("history_software_management_commands"); - // software_management_commands_group->set_header("Software Management Commands:"); - // cmd.register_group(software_management_commands_group); + auto * software_management_commands_group = parser.add_new_group("history_software_management_commands"); + software_management_commands_group->set_header("Software Management Commands:"); + cmd.register_group(software_management_commands_group); // register_subcommand(std::make_unique(get_context()), software_management_commands_group); // register_subcommand(std::make_unique(get_context()), software_management_commands_group); // register_subcommand(std::make_unique(get_context()), software_management_commands_group); // register_subcommand(std::make_unique(get_context()), software_management_commands_group); - // register_subcommand(std::make_unique(get_context()), software_management_commands_group); + register_subcommand(std::make_unique(get_context()), software_management_commands_group); } void HistoryCommand::pre_configure() { diff --git a/dnf5/commands/history/history_replay.cpp b/dnf5/commands/history/history_replay.cpp index 41e0fd2bd..8504df25a 100644 --- a/dnf5/commands/history/history_replay.cpp +++ b/dnf5/commands/history/history_replay.cpp @@ -19,12 +19,56 @@ along with libdnf. If not, see . #include "history_replay.hpp" +#include + namespace dnf5 { void HistoryReplayCommand::set_argument_parser() { - get_argument_parser_command()->set_description("Replay a transaction that was previously stored to a file"); + auto & cmd = *get_argument_parser_command(); + cmd.set_description("Replay a transaction that was previously stored to a file"); + auto & ctx = get_context(); + auto & parser = ctx.get_argument_parser(); + + auto * transaction_path_arg = parser.add_new_positional_arg("transaction-path", 1, nullptr, nullptr); + transaction_path_arg->set_description("Path to a stored stransaction to replay."); + transaction_path_arg->set_parse_hook_func([this]( + [[maybe_unused]] libdnf5::cli::ArgumentParser::PositionalArg * arg, + [[maybe_unused]] int argc, + const char * const argv[]) { + transaction_path = argv[0]; + return true; + }); + cmd.register_positional_arg(transaction_path_arg); + + auto skip_unavailable = std::make_unique(*this); + auto skip_broken = std::make_unique(*this); + + resolve = std::make_unique( + *this, "resolve", '\0', "Resolve the transaction again. TODO(amatej): enhance description", false); + ignore_installed = std::make_unique( + *this, "ignore-installed", '\0', "TODO(amatej): add", false); +} + +void HistoryReplayCommand::configure() { + auto & context = get_context(); + context.set_load_system_repo(true); + context.set_load_available_repos(Context::LoadAvailableRepos::ENABLED); } -void HistoryReplayCommand::run() {} +void HistoryReplayCommand::run() { + auto & context = get_context(); + replay = std::make_unique( + context.base.get_weak_ptr(), std::filesystem::path(transaction_path), ignore_installed->get_value()); + + if (resolve->get_value()) { + replay->fill_goal(*context.get_goal()); + } else { + context.set_transaction(replay->create_transaction()); + } +} + +void HistoryReplayCommand::goal_resolved() { + replay->fix_reasons(get_context().get_transaction()); +} } // namespace dnf5 diff --git a/dnf5/commands/history/history_replay.hpp b/dnf5/commands/history/history_replay.hpp index 9f379d930..fd89159c6 100644 --- a/dnf5/commands/history/history_replay.hpp +++ b/dnf5/commands/history/history_replay.hpp @@ -21,8 +21,11 @@ along with libdnf. If not, see . #ifndef DNF5_COMMANDS_HISTORY_HISTORY_REPLAY_HPP #define DNF5_COMMANDS_HISTORY_HISTORY_REPLAY_HPP -#include +#include "arguments.hpp" +#include +#include +#include namespace dnf5 { @@ -30,8 +33,18 @@ namespace dnf5 { class HistoryReplayCommand : public Command { public: explicit HistoryReplayCommand(Context & context) : Command(context, "replay") {} + void configure() override; void set_argument_parser() override; void run() override; + void goal_resolved() override; + +private: + std::string transaction_path; + + std::unique_ptr resolve{nullptr}; + std::unique_ptr ignore_installed{nullptr}; + + std::unique_ptr replay{nullptr}; };