diff --git a/dnf5-plugins/builddep_plugin/builddep.cpp b/dnf5-plugins/builddep_plugin/builddep.cpp index ed07f5c64..9cbb96934 100644 --- a/dnf5-plugins/builddep_plugin/builddep.cpp +++ b/dnf5-plugins/builddep_plugin/builddep.cpp @@ -20,6 +20,9 @@ along with libdnf. If not, see . #include "builddep.hpp" #include "utils/string.hpp" +#include "utils/url.hpp" + +#include "libdnf5/repo/file_downloader.hpp" #include #include @@ -136,19 +139,35 @@ void BuildDepCommand::parse_builddep_specs(int specs_count, const char * const s const std::string_view ext_srpm(".src.rpm"); const std::string_view ext_nosrpm(".nosrc.rpm"); std::set unique_items; + libdnf5::repo::FileDownloader downloader(get_context().get_base()); for (int i = 0; i < specs_count; ++i) { const std::string_view spec(specs[i]); + // Remote specs are downloaded to temp files which have random suffix. + // They cannot be used to compare extensions. + std::string spec_location(specs[i]); if (auto [it, inserted] = unique_items.emplace(spec); inserted) { - // TODO(mblaha): download remote URLs to temporary location + remove them afterwards + if (libdnf5::utils::url::is_url(spec_location)) { + if (spec_location.starts_with("file://")) { + spec_location = spec_location.substr(7); + } else { + // Download remote argument + downloaded_remotes.push_back(std::make_unique( + std::filesystem::path(spec_location).filename())); + downloader.add(specs[i], downloaded_remotes.back()->get_path()); + spec_location = downloaded_remotes.back()->get_path(); + } + } + if (spec.ends_with(ext_spec)) { - spec_file_paths.emplace_back(spec); + spec_file_paths.emplace_back(std::move(spec_location)); } else if (spec.ends_with(ext_srpm) || spec.ends_with(ext_nosrpm)) { - srpm_file_paths.emplace_back(spec); + srpm_file_paths.emplace_back(std::move(spec_location)); } else { - pkg_specs.emplace_back(spec); + pkg_specs.emplace_back(std::move(spec_location)); } } } + downloader.download(); } bool BuildDepCommand::add_from_spec_file( diff --git a/dnf5-plugins/builddep_plugin/builddep.hpp b/dnf5-plugins/builddep_plugin/builddep.hpp index fa0013c77..cd339ade9 100644 --- a/dnf5-plugins/builddep_plugin/builddep.hpp +++ b/dnf5-plugins/builddep_plugin/builddep.hpp @@ -22,6 +22,8 @@ along with libdnf. If not, see . #define DNF5_COMMANDS_BUILD_DEP_BUILD_DEP_HPP +#include "libdnf5/utils/fs/temp.hpp" + #include #include #include @@ -55,6 +57,9 @@ class BuildDepCommand : public Command { std::vector srpm_file_paths{}; std::vector> rpm_macros{}; + // Args downloaded into temp files which are automatically cleaned up + std::vector> downloaded_remotes{}; + std::unique_ptr allow_erasing; };