Skip to content

Commit

Permalink
package_downloader: Always call download callbacks
Browse files Browse the repository at this point in the history
The download callbacks were not called in case the source and
destination of locally available downloaded file were the same.
  • Loading branch information
m-blaha committed Aug 14, 2024
1 parent 1e83b07 commit 3aebdbb
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions libdnf5/repo/package_downloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,25 @@ void PackageDownloader::download() try {
std::filesystem::path source = pkg_target.package.get_package_path();
std::filesystem::path destination = pkg_target.destination / source.filename();
std::error_code ec;
if (!std::filesystem::equivalent(source, destination, ec)) {
const bool same_file = std::filesystem::equivalent(source, destination, ec);
if (!same_file) {
std::filesystem::copy(source, destination, std::filesystem::copy_options::overwrite_existing, ec);
if (auto * download_callbacks = pkg_target.package.get_base()->get_download_callbacks()) {
std::string msg;
DownloadCallbacks::TransferStatus status;
if (ec) {
status = DownloadCallbacks::TransferStatus::ERROR;
msg = ec.message();
}
if (auto * download_callbacks = pkg_target.package.get_base()->get_download_callbacks()) {
std::string msg;
DownloadCallbacks::TransferStatus status;
if (ec) {
status = DownloadCallbacks::TransferStatus::ERROR;
msg = ec.message();
} else {
status = DownloadCallbacks::TransferStatus::ALREADYEXISTS;
if (same_file) {
msg = "Already downloaded";
} else {
status = DownloadCallbacks::TransferStatus::ALREADYEXISTS;
msg = fmt::format("Copied from {}", source.string());
}
download_callbacks->end(pkg_target.user_cb_data, status, msg.c_str());
}
download_callbacks->end(pkg_target.user_cb_data, status, msg.c_str());
}
continue;
}
Expand Down

0 comments on commit 3aebdbb

Please sign in to comment.