Skip to content

Commit

Permalink
Enable history replay command
Browse files Browse the repository at this point in the history
It uses TransactionReplay.
There is a new argument `--resolve` which determines if the loaded
transaction is resolved again through Goal or not.
  • Loading branch information
kontura committed Oct 18, 2023
1 parent 2069789 commit c2b3b16
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 7 deletions.
8 changes: 4 additions & 4 deletions dnf5/commands/history/history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ void HistoryCommand::register_subcommands() {
register_subcommand(std::make_unique<HistoryInfoCommand>(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<HistoryUndoCommand>(get_context()), software_management_commands_group);
// register_subcommand(std::make_unique<HistoryRedoCommand>(get_context()), software_management_commands_group);
// register_subcommand(std::make_unique<HistoryRollbackCommand>(get_context()), software_management_commands_group);
// register_subcommand(std::make_unique<HistoryStoreCommand>(get_context()), software_management_commands_group);
// register_subcommand(std::make_unique<HistoryReplayCommand>(get_context()), software_management_commands_group);
register_subcommand(std::make_unique<HistoryReplayCommand>(get_context()), software_management_commands_group);
}

void HistoryCommand::pre_configure() {
Expand Down
48 changes: 46 additions & 2 deletions dnf5/commands/history/history_replay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,56 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

#include "history_replay.hpp"

#include <dnf5/shared_options.hpp>

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<SkipUnavailableOption>(*this);
auto skip_broken = std::make_unique<SkipBrokenOption>(*this);

resolve = std::make_unique<libdnf5::cli::session::BoolOption>(
*this, "resolve", '\0', "Resolve the transaction again. TODO(amatej): enhance description", false);
ignore_installed = std::make_unique<libdnf5::cli::session::BoolOption>(
*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<libdnf5::transaction::TransactionReplay>(
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
15 changes: 14 additions & 1 deletion dnf5/commands/history/history_replay.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,30 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#ifndef DNF5_COMMANDS_HISTORY_HISTORY_REPLAY_HPP
#define DNF5_COMMANDS_HISTORY_HISTORY_REPLAY_HPP

#include <dnf5/context.hpp>
#include "arguments.hpp"

#include <dnf5/context.hpp>
#include <libdnf5/conf/option_bool.hpp>
#include <libdnf5/transaction/transaction_replay.hpp>

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<libdnf5::cli::session::BoolOption> resolve{nullptr};
std::unique_ptr<libdnf5::cli::session::BoolOption> ignore_installed{nullptr};

std::unique_ptr<libdnf5::transaction::TransactionReplay> replay{nullptr};
};


Expand Down

0 comments on commit c2b3b16

Please sign in to comment.