Skip to content

Commit

Permalink
download: add --source option
Browse files Browse the repository at this point in the history
  • Loading branch information
principis committed Jan 28, 2024
1 parent e5786a8 commit 4f5c868
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
33 changes: 33 additions & 0 deletions dnf5/commands/download/download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,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))));

source_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 @@ -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");
Expand Down Expand Up @@ -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);
}
Expand All @@ -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, ".");
Expand Down Expand Up @@ -179,6 +194,24 @@ void DownloadCommand::run() {
return;
}

if (source_option->get_value()) {
std::map<std::string, libdnf5::rpm::Package> 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()) {
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 @@ -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<std::unique_ptr<libdnf5::Option>> * patterns_to_download_options{nullptr};
};
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 @@ -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
Expand All @@ -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
========
Expand Down

0 comments on commit 4f5c868

Please sign in to comment.