Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements and fixes for storing transactions #1585

Merged
merged 5 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions dnf5/commands/history/history_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

#include "commands/history/transaction_id.hpp"

#include <fmt/format.h>
#include <libdnf5-cli/utils/userconfirm.hpp>
#include <libdnf5/utils/bgettext/bgettext-mark-domain.h>
#include <libdnf5/utils/fs/temp.hpp>
Expand All @@ -37,14 +38,14 @@ void HistoryStoreCommand::set_argument_parser() {

output_option = dynamic_cast<libdnf5::OptionString *>(
parser.add_init_value(std::make_unique<libdnf5::OptionString>("./transaction")));
auto query_format = parser.add_new_named_arg("output");
query_format->set_long_name("output");
query_format->set_short_name('o');
query_format->set_description("Path to a directory for storing the transaction, default is \"./transaction\"");
query_format->set_has_value(true);
query_format->set_arg_value_help("PATH");
query_format->link_value(output_option);
cmd.register_named_arg(query_format);
auto output_arg = parser.add_new_named_arg("output");
output_arg->set_long_name("output");
output_arg->set_short_name('o');
output_arg->set_description("Path to a directory for storing the transaction, default is \"./transaction\"");
output_arg->set_has_value(true);
output_arg->set_arg_value_help("PATH");
output_arg->link_value(output_option);
cmd.register_named_arg(output_arg);

transaction_specs = std::make_unique<TransactionSpecArguments>(*this);
}
Expand Down Expand Up @@ -76,7 +77,7 @@ void HistoryStoreCommand::run() {
}

if (transactions.empty()) {
throw libdnf5::cli::CommandExitError(1, M_("No transactions selected for storing, exactly one required."));
throw libdnf5::cli::CommandExitError(1, M_("No matching transaction ID found, exactly one required."));
}
if (transactions.size() != 1) {
throw libdnf5::cli::CommandExitError(1, M_("Multiple transactions selected for storing, only one allowed."));
Expand All @@ -91,6 +92,7 @@ void HistoryStoreCommand::run() {

std::filesystem::rename(tmp_file.get_path(), trans_file_path);
tmp_file.release();
get_context().print_info(fmt::format("Transaction saved to {}.", output_option->get_value()));
}

} // namespace dnf5
8 changes: 3 additions & 5 deletions libdnf5/transaction/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,17 +263,14 @@ void Transaction::fill_transaction_groups(
new_grp.set_repoid(*tsgrp.get_group().get_repos().begin());
}

libdnf5::comps::PackageType package_types{0};
for (const auto & group_package : group.get_packages()) {
auto & new_grp_pkg = new_grp.new_package();
auto name = group_package.get_name();
new_grp_pkg.set_name(name);
new_grp_pkg.set_package_type(group_package.get_type());
new_grp_pkg.set_installed(installed_names.contains(name) ? true : false);
package_types |= group_package.get_type();
}

new_grp.set_package_types(package_types);
new_grp.set_package_types(tsgrp.get_package_types());
}
}

Expand Down Expand Up @@ -334,7 +331,8 @@ std::string Transaction::serialize() {
for (const auto & pkg : get_packages()) {
PackageReplay package_replay;

package_replay.nevra = pkg.to_string();
// Use to_nevra_string in order to have nevra wihtout epoch if it is 0
package_replay.nevra = rpm::to_nevra_string(pkg);
package_replay.action = pkg.get_action();
package_replay.reason = pkg.get_reason();
package_replay.repo_id = pkg.get_repoid();
Expand Down
Loading