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

Warn on sign conversion #1703

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Changes from 1 commit
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
35 changes: 25 additions & 10 deletions dnf5/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#include <cstring>
#include <filesystem>
#include <iostream>
#include <utility>

constexpr const char * DNF5_LOGGER_FILENAME = "dnf5.log";

Expand Down Expand Up @@ -773,29 +774,38 @@ static void print_versions(Context & context) {
}

static void print_transaction_size_stats(Context & context) {
int64_t in_pkgs_size{0};
int64_t download_pkgs_size{0};
int64_t install_size{0};
int64_t remove_size{0};
unsigned long long int in_pkgs_size{0};
unsigned long long int download_pkgs_size{0};
unsigned long long int install_size{0};
unsigned long long int remove_size{0};

for (const auto & trans_pkg : context.get_transaction()->get_transaction_packages()) {
const auto pkg = trans_pkg.get_package();
if (transaction_item_action_is_inbound(trans_pkg.get_action())) {
const auto pkg_size = pkg.get_download_size();
in_pkgs_size += pkg_size;
if (in_pkgs_size < pkg_size)
return;
if (!pkg.is_available_locally()) {
download_pkgs_size += pkg_size;
if (download_pkgs_size < pkg_size)
return;
}
install_size += pkg.get_install_size();
if (install_size < pkg.get_install_size())
return;
} else if (transaction_item_action_is_outbound(trans_pkg.get_action())) {
remove_size += pkg.get_install_size();
if (remove_size < pkg.get_install_size())
return;
}
}

if (in_pkgs_size != 0) {
const auto [in_pkgs_size_value, in_pkgs_size_unit] = libdnf5::cli::utils::units::to_size(in_pkgs_size);
if (in_pkgs_size != 0 && std::in_range<int64_t>(in_pkgs_size) && std::in_range<int64_t>(download_pkgs_size)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::in_range<int64_t>(in_pkgs_size) - Maybe a bit unnecessary test. The transaction will not exceed 8 exabytes in the near future. And if it does, I suspect there will be more serious problems on other places. :-)

const auto [in_pkgs_size_value, in_pkgs_size_unit] =
libdnf5::cli::utils::units::to_size(static_cast<int64_t>(in_pkgs_size));
const auto [dwnl_pkgs_size_value, dwnl_pkgs_size_unit] =
libdnf5::cli::utils::units::to_size(download_pkgs_size);
libdnf5::cli::utils::units::to_size(static_cast<int64_t>(download_pkgs_size));
context.print_info(libdnf5::utils::sformat(
_("Total size of inbound packages is {:.0f} {:s}. Need to download {:.0f} {:s}."),
in_pkgs_size_value,
Expand All @@ -804,9 +814,14 @@ static void print_transaction_size_stats(Context & context) {
dwnl_pkgs_size_unit));
}

const auto [install_size_value, install_size_unit] = libdnf5::cli::utils::units::to_size(install_size);
const auto [remove_size_value, remove_size_unit] = libdnf5::cli::utils::units::to_size(remove_size);
const auto size_diff = install_size - remove_size;
if (!std::in_range<int64_t>(install_size) || !std::in_range<int64_t>(remove_size) ||
!std::in_range<int64_t>(install_size - remove_size))
return;
const auto [install_size_value, install_size_unit] =
libdnf5::cli::utils::units::to_size(static_cast<int64_t>(install_size));
const auto [remove_size_value, remove_size_unit] =
libdnf5::cli::utils::units::to_size(static_cast<int64_t>(remove_size));
const int64_t size_diff = static_cast<int64_t>(install_size - remove_size);
const auto [size_diff_value, size_diff_unit] = libdnf5::cli::utils::units::to_size(std::abs(size_diff));
if (size_diff >= 0) {
context.print_info(libdnf5::utils::sformat(
Expand Down