Skip to content

Commit

Permalink
Added url option
Browse files Browse the repository at this point in the history
  • Loading branch information
derickdiaz authored and kontura committed Jan 22, 2024
1 parent 0b57dd0 commit 1461a37
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
41 changes: 31 additions & 10 deletions dnf5/commands/download/download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ void DownloadCommand::set_argument_parser() {
alldeps_option = dynamic_cast<libdnf5::OptionBool *>(
parser.add_init_value(std::unique_ptr<libdnf5::OptionBool>(new libdnf5::OptionBool(false))));

url_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 @@ -77,10 +80,17 @@ void DownloadCommand::set_argument_parser() {
alldeps->set_const_value("true");
alldeps->link_value(alldeps_option);

auto url = parser.add_new_named_arg("url");
url->set_long_name("url");
url->set_description("Print the list of urls where the rpms can be downloaded instead of downloading");
url->set_const_value("true");
url->link_value(url_option);

cmd.register_named_arg(alldeps);
create_destdir_option(*this);
cmd.register_named_arg(resolve);
cmd.register_positional_arg(keys);
cmd.register_named_arg(url);
}

void DownloadCommand::configure() {
Expand Down Expand Up @@ -146,20 +156,31 @@ void DownloadCommand::run() {
}
}

if (!download_pkgs.empty()) {
libdnf5::repo::PackageDownloader downloader(ctx.base);

// for download command, we don't want to mark the packages for removal
downloader.force_keep_packages(true);
if (download_pkgs.empty()) {
return;
}

for (auto & [nevra, pkg] : download_pkgs) {
downloader.add(pkg);
if (url_option->get_value()) {
for (auto & [nerva, pkg] : download_pkgs) {
auto urls = pkg.get_remote_locations();
libdnf_assert(!urls.empty(), "Failed to get mirror for package: \"{}\"", pkg.get_name());
std::cout << urls[0] << std::endl;
}
return;
}
libdnf5::repo::PackageDownloader downloader(ctx.base);

// for download command, we don't want to mark the packages for removal
downloader.force_keep_packages(true);

std::cout << "Downloading Packages:" << std::endl;
downloader.download();
std::cout << std::endl;
for (auto & [nevra, pkg] : download_pkgs) {
downloader.add(pkg);
}

std::cout << "Downloading Packages:" << std::endl;
downloader.download();
std::cout << std::endl;
}


} // namespace dnf5
1 change: 1 addition & 0 deletions dnf5/commands/download/download.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class DownloadCommand : public Command {
private:
libdnf5::OptionBool * resolve_option{nullptr};
libdnf5::OptionBool * alldeps_option{nullptr};
libdnf5::OptionBool * url_option{nullptr};

std::vector<std::unique_ptr<libdnf5::Option>> * patterns_to_download_options{nullptr};
};
Expand Down

0 comments on commit 1461a37

Please sign in to comment.