Skip to content

Commit c40c685

Browse files
committed
images: Use indicatif::BinaryBytes for size formatting
Replace custom format_size() function with indicatif::BinaryBytes for consistent binary size formatting across the codebase. Also make DiskImageMetadata::compute_cache_hash() public for use by base_disks module. Signed-off-by: Claude <[email protected]> Signed-off-by: Colin Walters <[email protected]>
1 parent 36328aa commit c40c685

File tree

2 files changed

+2
-20
lines changed

2 files changed

+2
-20
lines changed

crates/kit/src/cache_metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub struct DiskImageMetadata {
7070

7171
impl DiskImageMetadata {
7272
/// Generate SHA256 hash of all build inputs
73-
fn compute_cache_hash(&self) -> String {
73+
pub fn compute_cache_hash(&self) -> String {
7474
let inputs = CacheInputs {
7575
image_digest: self.digest.clone(),
7676
filesystem: self.filesystem.clone(),

crates/kit/src/images.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl ImagesOpts {
6969
.map(|dt| format_relative_time(dt))
7070
.unwrap_or_else(|| "N/A".to_string());
7171

72-
let size = format_size(image.size);
72+
let size = indicatif::BinaryBytes(image.size).to_string();
7373

7474
table.add_row(vec![repository, tag, id.to_string(), created, size]);
7575
}
@@ -116,24 +116,6 @@ pub struct ImageInspect {
116116
pub created: Option<chrono::DateTime<chrono::Utc>>,
117117
}
118118

119-
/// Format bytes into human-readable size string.
120-
fn format_size(bytes: u64) -> String {
121-
const UNITS: &[&str] = &["B", "KB", "MB", "GB", "TB"];
122-
let mut size = bytes as f64;
123-
let mut unit_idx = 0;
124-
125-
while size >= 1024.0 && unit_idx < UNITS.len() - 1 {
126-
size /= 1024.0;
127-
unit_idx += 1;
128-
}
129-
130-
if unit_idx == 0 {
131-
format!("{} {}", size as u64, UNITS[unit_idx])
132-
} else {
133-
format!("{:.1} {}", size, UNITS[unit_idx])
134-
}
135-
}
136-
137119
/// Format a datetime as relative time (e.g., "2 hours ago", "3 days ago").
138120
fn format_relative_time(dt: chrono::DateTime<chrono::Utc>) -> String {
139121
let now = chrono::Utc::now();

0 commit comments

Comments
 (0)