From 4f5c868201db646a4cfc46b97694baaceefe7d4b Mon Sep 17 00:00:00 2001 From: Arthur Bols Date: Sun, 28 Jan 2024 17:45:45 +0100 Subject: [PATCH] download: add `--source` option --- dnf5/commands/download/download.cpp | 33 +++++++++++++++++++++++++++++ dnf5/commands/download/download.hpp | 1 + doc/commands/download.8.rst | 4 ++++ 3 files changed, 38 insertions(+) diff --git a/dnf5/commands/download/download.cpp b/dnf5/commands/download/download.cpp index 8d0178ac58..29327bbc19 100644 --- a/dnf5/commands/download/download.cpp +++ b/dnf5/commands/download/download.cpp @@ -67,6 +67,9 @@ void DownloadCommand::set_argument_parser() { url_option = dynamic_cast( parser.add_init_value(std::unique_ptr(new libdnf5::OptionBool(false)))); + source_option = dynamic_cast( + parser.add_init_value(std::unique_ptr(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"); @@ -80,6 +83,12 @@ void DownloadCommand::set_argument_parser() { alldeps->set_const_value("true"); alldeps->link_value(alldeps_option); + auto source = parser.add_new_named_arg("source"); + source->set_long_name("source"); + source->set_description("Download the src.rpm instead"); + source->set_const_value("true"); + source->link_value(source_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"); @@ -108,6 +117,7 @@ void DownloadCommand::set_argument_parser() { create_destdir_option(*this); cmd.register_named_arg(resolve); cmd.register_positional_arg(keys); + cmd.register_named_arg(source); cmd.register_named_arg(url); cmd.register_named_arg(urlprotocol); } @@ -131,6 +141,11 @@ void DownloadCommand::configure() { } else { context.set_load_system_repo(false); } + + if (source_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, "."); @@ -179,6 +194,24 @@ void DownloadCommand::run() { return; } + if (source_option->get_value()) { + std::map source_pkgs; + + for (auto & [nevra, pkg] : download_pkgs) { + libdnf5::rpm::PackageQuery pkg_query(full_pkg_query); + pkg_query.resolve_pkg_spec(pkg.get_source_name(), {}, true); + pkg_query.filter_arch({"src"}); + pkg_query.filter_available(); + pkg_query.filter_latest_evr(); + + for (const auto & spkg : pkg_query) { + source_pkgs.insert(create_nevra_pkg_pair(spkg)); + } + } + + 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()) { diff --git a/dnf5/commands/download/download.hpp b/dnf5/commands/download/download.hpp index 9c787587fb..e70a1672f6 100644 --- a/dnf5/commands/download/download.hpp +++ b/dnf5/commands/download/download.hpp @@ -46,6 +46,7 @@ class DownloadCommand : public Command { libdnf5::OptionBool * resolve_option{nullptr}; libdnf5::OptionBool * alldeps_option{nullptr}; libdnf5::OptionBool * url_option{nullptr}; + libdnf5::OptionBool * source_option{nullptr}; std::vector> * patterns_to_download_options{nullptr}; }; diff --git a/doc/commands/download.8.rst b/doc/commands/download.8.rst index 4d97f4d8f8..9aa40013e9 100644 --- a/doc/commands/download.8.rst +++ b/doc/commands/download.8.rst @@ -53,6 +53,8 @@ Options ``--urlprotocol`` | To be used together with ``--url``. It filters out the URLs to the specified protocols: ``http``, ``https``, ``ftp``, or ``file``. This option can be used multiple times. +``--source`` + | Download the source rpm. Enables source repositories of all enabled binary repositories. Examples @@ -73,6 +75,8 @@ Examples ``dnf5 download --url --urlprotocol http python`` | List the http URL to download the python package +``dnf5 download dnf5 --source`` + | Download the ``dnf5`` source rpm. See Also ========