Backport fix for single-decimal restoration

Related: #RHEL-93001

Restore single-decimal precision to stream output

Backport https://github.com/coreos/coreos-installer/pull/1654
This commit is contained in:
Aashish Radhakrishnan 2025-07-18 13:09:26 -04:00
parent 5402031262
commit c7846a2c64
2 changed files with 75 additions and 1 deletions

View File

@ -0,0 +1,67 @@
From dbc41bad9de728f1d42000c5633e3494126f9d6d Mon Sep 17 00:00:00 2001
From: Dusty Mabe <dusty@dustymabe.com>
Date: Thu, 1 May 2025 17:36:39 -0400
Subject: [PATCH] download: format byte unit with 1 decimal place precision
Prior to v0.24.1 the output when processing a stream of disk image
input the output would write with 1 decimal place of precision:
```
Read disk 118.2 MiB/2.6 GiB (4%)
Read disk 157.0 MiB/2.6 GiB (5%)
Read disk 300.1 MiB/2.6 GiB (11%)
Read disk 450.6 MiB/2.6 GiB (16%)
Read disk 515.2 MiB/2.6 GiB (19%)
```
After v0.24.1 it has many decimal places of precision:
```
Read disk 138.2265625 MiB/2.59765625 GiB (5%)
Read disk 265.6722106933594 MiB/2.59765625 GiB (9%)
Read disk 399.67578125 MiB/2.59765625 GiB (15%)
Read disk 519.40625 MiB/2.59765625 GiB (19%)
Read disk 597.5625 MiB/2.59765625 GiB (22%)
```
This is likely due to 68198d0. Let's get back the previous formatting.
---
docs/release-notes.md | 2 +-
src/download.rs | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/docs/release-notes.md b/docs/release-notes.md
index 42b4974..19b8324 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -8,9 +8,9 @@ nav_order: 8
Major changes:
-
Minor changes:
+- Restore formatting of progress reporting to pre 0.24.0 behavior.
Internal changes:
diff --git a/src/download.rs b/src/download.rs
index f57fca3..e5b967c 100644
--- a/src/download.rs
+++ b/src/download.rs
@@ -456,9 +456,9 @@ impl<'a, R: Read> ProgressReader<'a, R> {
/// Format a size in bytes.
fn format_bytes(count: u64) -> String {
- Byte::from_u64(count)
- .get_appropriate_unit(byte_unit::UnitType::Binary)
- .to_string()
+ let adjusted_byte = Byte::from_u64(count).get_appropriate_unit(byte_unit::UnitType::Binary);
+ // Get a string trimmed to 1 decimal place of precision
+ format!("{adjusted_byte:.1}")
}
}
--
2.47.0

View File

@ -12,7 +12,7 @@
Name: rust-%{crate}
Version: 0.24.0
Release: 1%{?dist}
Release: 2%{?dist}
Summary: Installer for Fedora CoreOS and RHEL CoreOS
# Upstream license specification: Apache-2.0
@ -23,6 +23,9 @@ Source0: https://crates.io/api/v1/crates/%{crate}/%{version}/download#/%{
Source1: https://github.com/coreos/%{crate}/releases/download/v%{version}/%{crate}-%{version}-vendor.tar.gz
Source2: https://github.com/coreos/coreos-installer-dracut/archive/%{dracutcommit}/coreos-installer-dracut-%{dracutshortcommit}.tar.gz
# https://github.com/coreos/coreos-installer/pull/1654
Patch0: 0001-download-format-byte-unit-with-1-decimal-place-preci.patch
ExclusiveArch: %{rust_arches}
%if 0%{?rhel} && !0%{?eln}
BuildRequires: rust-toolset
@ -173,6 +176,10 @@ from the initramfs.
%endif
%changelog
* Fri Jul 18 2025 Aashish Radhakrishnan <aaradhak@redhat.com> - 0.24.0-2
- Restore single-decimal precision to stream output
Backport https://github.com/coreos/coreos-installer/pull/1654
* Wed Apr 16 2025 Joel Capitao <jcapitao@redhat.com> - 0.24.0-1
- Update to latest upstream