Skip to content

Commit

Permalink
package_downloader: Handle local files
Browse files Browse the repository at this point in the history
Local packages are not passed to librepo for download, but directly
copied to the destination directory.
  • Loading branch information
m-blaha committed Jul 16, 2024
1 parent 74e0177 commit 9ab4e87
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions libdnf5/repo/package_downloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ void PackageDownloader::download() try {

auto & config = p_impl->base->get_config();
auto use_cache_only = config.get_cacheonly_option().get_value() == "all";
// map package.location->destination
std::map<std::filesystem::path, std::filesystem::path> local_files;

GError * err{nullptr};

Expand All @@ -150,6 +152,11 @@ void PackageDownloader::download() try {

std::filesystem::create_directory(pkg_target.destination);

if (pkg_target.package.is_available_locally()) {
local_files[pkg_target.package.get_location()] = pkg_target.destination;
continue;
}

if (auto * download_callbacks = pkg_target.package.get_base()->get_download_callbacks()) {
pkg_target.user_cb_data = download_callbacks->add_new_download(
pkg_target.user_data,
Expand Down Expand Up @@ -181,6 +188,15 @@ void PackageDownloader::download() try {
lr_targets.emplace_back(lr_target);
}

// Copy local packages to their destination directories
for (const auto & [source, destination] : local_files) {
auto dest = destination / source.filename();
std::error_code ec;
if (!std::filesystem::equivalent(source, dest, ec)) {
std::filesystem::copy(source, dest, std::filesystem::copy_options::overwrite_existing);
}
}

// Adding items to the end of GSList is slow. We go from the back and add items to the beginning.
GSList * list{nullptr};
for (auto it = lr_targets.rbegin(); it != lr_targets.rend(); ++it) {
Expand Down

0 comments on commit 9ab4e87

Please sign in to comment.