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

Url option #1155

Merged
merged 1 commit into from
Jan 22, 2024
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
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);

derickdiaz marked this conversation as resolved.
Show resolved Hide resolved
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
Loading