Skip to content

Commit

Permalink
download: add --srpm option
Browse files Browse the repository at this point in the history
  • Loading branch information
principis committed Feb 16, 2024
1 parent d241bb4 commit 146145a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
47 changes: 47 additions & 0 deletions dnf5/commands/download/download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ void DownloadCommand::set_argument_parser() {
url_option = dynamic_cast<libdnf5::OptionBool *>(
parser.add_init_value(std::unique_ptr<libdnf5::OptionBool>(new libdnf5::OptionBool(false))));

srpm_option = dynamic_cast<libdnf5::OptionBool *>(
parser.add_init_value(std::unique_ptr<libdnf5::OptionBool>(new libdnf5::OptionBool(false))));

auto resolve = parser.add_new_named_arg("resolve");
resolve->set_long_name("resolve");
resolve->set_description("Resolve and download needed dependencies");
Expand All @@ -82,6 +85,12 @@ void DownloadCommand::set_argument_parser() {
alldeps->set_const_value("true");
alldeps->link_value(alldeps_option);

auto srpm = parser.add_new_named_arg("srpm");
srpm->set_long_name("srpm");
srpm->set_description("Download the src.rpm instead");
srpm->set_const_value("true");
srpm->link_value(srpm_option);

auto url = parser.add_new_named_arg("url");
url->set_long_name("url");
url->set_description("Print a URL where the rpms can be downloaded instead of downloading");
Expand Down Expand Up @@ -140,6 +149,7 @@ void DownloadCommand::set_argument_parser() {
create_destdir_option(*this);
cmd.register_named_arg(resolve);
cmd.register_positional_arg(keys);
cmd.register_named_arg(srpm);
cmd.register_named_arg(url);
cmd.register_named_arg(urlprotocol);
cmd.register_named_arg(arch);
Expand All @@ -164,6 +174,11 @@ void DownloadCommand::configure() {
} else {
context.set_load_system_repo(false);
}

if (srpm_option->get_value()) {
context.base.get_repo_sack()->enable_source_repos();
}

context.set_load_available_repos(Context::LoadAvailableRepos::ENABLED);
// Default destination for downloaded rpms is the current directory
context.base.get_config().get_destdir_option().set(libdnf5::Option::Priority::PLUGINDEFAULT, ".");
Expand Down Expand Up @@ -215,6 +230,38 @@ void DownloadCommand::run() {
return;
}

if (srpm_option->get_value()) {
std::map<std::string, libdnf5::rpm::Package> source_pkgs;

libdnf5::rpm::PackageQuery source_pkg_query(ctx.base);
source_pkg_query.filter_arch({"src"});
source_pkg_query.filter_available();

for (auto & [nevra, pkg] : download_pkgs) {
auto sourcerpm = pkg.get_sourcerpm();

if (!sourcerpm.empty()) {
libdnf5::rpm::PackageQuery pkg_query(source_pkg_query);
pkg_query.filter_epoch({pkg.get_epoch()});

// Remove ".rpm" to get sourcerpm nevra
sourcerpm.erase(sourcerpm.length() - 4);
pkg_query.resolve_pkg_spec(sourcerpm, {}, true);

for (const auto & spkg : pkg_query) {
source_pkgs.insert(create_nevra_pkg_pair(spkg));
}
} else if (pkg.get_arch() == "src") {
source_pkgs.insert(create_nevra_pkg_pair(pkg));
} else {
ctx.base.get_logger()->info("No source rpm defined for package: \"{}\"", pkg.get_name());
continue;
}
}

download_pkgs = source_pkgs;
}

if (url_option->get_value()) {
// If no urlprotocols are specified, all values within the urlprotocol_valid_options will be used
if (urlprotocol_option.empty()) {
Expand Down
1 change: 1 addition & 0 deletions dnf5/commands/download/download.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class DownloadCommand : public Command {
libdnf5::OptionBool * resolve_option{nullptr};
libdnf5::OptionBool * alldeps_option{nullptr};
libdnf5::OptionBool * url_option{nullptr};
libdnf5::OptionBool * srpm_option{nullptr};

std::vector<std::unique_ptr<libdnf5::Option>> * patterns_to_download_options{nullptr};
};
Expand Down
4 changes: 4 additions & 0 deletions doc/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ Downgrade command
* When any argument does not match any package or it is not installed, DNF5 fail. The behavior can be modified by
the ``--skip-unavailable`` option.

Download command
----------------
* Option ``--source`` was renamed to ``--srpm``.

Group command
-------------
* Dropped ``group mark install`` and ``group mark remove`` subcommands in favour of the
Expand Down
4 changes: 4 additions & 0 deletions doc/commands/download.8.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ Options
``--arch``
| Limit to packages of given architectures. This option can be used multiple times.
``--srpm``
| Download the source rpm. Enables source repositories of all enabled binary repositories.
Examples
========
Expand All @@ -78,6 +80,8 @@ Examples
``dnf5 download python --arch x86_64``
| Downloads python with the ``x86_64`` architecture.
``dnf5 download dnf5 --srpm``
| Download the ``dnf5`` source rpm.
See Also
========
Expand Down

0 comments on commit 146145a

Please sign in to comment.