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

Add support for downloadonly in DNF5 #559

Merged
merged 3 commits into from
May 29, 2023
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
1 change: 1 addition & 0 deletions dnf5/commands/downgrade/downgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ void DowngradeCommand::set_argument_parser() {
cmd.register_positional_arg(keys);

allow_erasing = std::make_unique<AllowErasingOption>(*this);
create_downloadonly_option(*this);
auto skip_unavailable = std::make_unique<SkipUnavailableOption>(*this);
auto skip_broken = std::make_unique<SkipBrokenOption>(*this);
create_allow_downgrade_options(*this);
Expand Down
1 change: 1 addition & 0 deletions dnf5/commands/group/group_install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void GroupInstallCommand::set_argument_parser() {
auto skip_unavailable = std::make_unique<SkipUnavailableOption>(*this);
auto skip_broken = std::make_unique<SkipBrokenOption>(*this);
create_allow_downgrade_options(*this);
create_downloadonly_option(*this);
}

void GroupInstallCommand::configure() {
Expand Down
1 change: 1 addition & 0 deletions dnf5/commands/install/install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void InstallCommand::set_argument_parser() {
cmd.register_positional_arg(keys);

allow_erasing = std::make_unique<AllowErasingOption>(*this);
create_downloadonly_option(*this);

advisory_name = std::make_unique<AdvisoryOption>(*this);
advisory_security = std::make_unique<SecurityOption>(*this);
Expand Down
1 change: 1 addition & 0 deletions dnf5/commands/reinstall/reinstall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ void ReinstallCommand::set_argument_parser() {
keys->set_complete_hook_func([&ctx](const char * arg) { return match_specs(ctx, arg, true, false, true, true); });
cmd.register_positional_arg(keys);

create_downloadonly_option(*this);
auto skip_unavailable = std::make_unique<SkipUnavailableOption>(*this);
auto skip_broken = std::make_unique<SkipBrokenOption>(*this);
create_allow_downgrade_options(*this);
Expand Down
1 change: 1 addition & 0 deletions dnf5/commands/upgrade/upgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ void UpgradeCommand::set_argument_parser() {
allow_erasing = std::make_unique<AllowErasingOption>(*this);
auto skip_unavailable = std::make_unique<SkipUnavailableOption>(*this);
create_allow_downgrade_options(*this);
create_downloadonly_option(*this);

advisory_name = std::make_unique<AdvisoryOption>(*this);
advisory_security = std::make_unique<SecurityOption>(*this);
Expand Down
4 changes: 4 additions & 0 deletions dnf5/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,10 @@ bool Context::check_gpg_signatures(libdnf::base::Transaction & transaction) {
void Context::download_and_run(libdnf::base::Transaction & transaction) {
transaction.download();

if (base.get_config().get_downloadonly_option().get_value()) {
return;
}

std::cout << std::endl << "Verifying PGP signatures" << std::endl;
if (!check_gpg_signatures(transaction)) {
throw libdnf::cli::CommandExitError(1, M_("Signature verification failed"));
Expand Down
4 changes: 4 additions & 0 deletions dnf5/include/dnf5/shared_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ void create_allow_downgrade_options(dnf5::Command & command);
/// The values are stored in the `destdir` configuration option
void create_destdir_option(dnf5::Command & command);

/// Create the `--downloadonly` option for a command provided as an argument.
/// The values are stored in the `downloadonly` configuration option
void create_downloadonly_option(dnf5::Command & command);


} // namespace dnf5

Expand Down
16 changes: 10 additions & 6 deletions dnf5/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -769,12 +769,16 @@ int main(int argc, char * argv[]) try {

dnf5::print_transaction_size_stats(context);

for (const auto & tsflag : base.get_config().get_tsflags_option().get_value()) {
if (tsflag == "test") {
std::cout
<< "Test mode enabled: Only package downloads, pgp key installations and transaction checks "
"will be performed."
<< std::endl;
if (base.get_config().get_downloadonly_option().get_value()) {
std::cout << "The operation will only download packages for the transaction." << std::endl;
} else {
for (const auto & tsflag : base.get_config().get_tsflags_option().get_value()) {
if (tsflag == "test") {
std::cout << "Test mode enabled: Only package downloads, pgp key installations and transaction "
"checks "
"will be performed."
jan-kolarik marked this conversation as resolved.
Show resolved Hide resolved
<< std::endl;
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions dnf5/shared_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,15 @@ void create_destdir_option(dnf5::Command & command) {
command.get_argument_parser_command()->register_named_arg(destdir);
}

void create_downloadonly_option(dnf5::Command & command) {
auto & parser = command.get_context().get_argument_parser();
auto downloadonly = parser.add_new_named_arg("downloadonly");
downloadonly->set_long_name("downloadonly");
downloadonly->set_description("Only download packages for a transaction");
downloadonly->set_const_value("true");
downloadonly->link_value(&command.get_context().base.get_config().get_downloadonly_option());
command.get_argument_parser_command()->register_named_arg(downloadonly);
}


} // namespace dnf5