From 566a0b44c0dcd0e0b48ae043375a6c30afd42221 Mon Sep 17 00:00:00 2001 From: Gwen Lg Date: Thu, 29 Jan 2026 00:09:54 +0100 Subject: [PATCH] chore: update bytesize dependency to 2.3 include code update to follow display management change. --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/garage/cli/remote/bucket.rs | 18 +++++++----------- src/garage/cli/remote/layout.rs | 4 ++-- src/rpc/layout/mod.rs | 2 +- src/rpc/layout/version.rs | 22 ++++++++++++---------- 6 files changed, 25 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0775a37c..efccf027 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -673,9 +673,9 @@ dependencies = [ [[package]] name = "bytesize" -version = "1.3.3" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e93abca9e28e0a1b9877922aacb20576e05d4679ffa78c3d6dc22a26a216659" +checksum = "6bd91ee7b2422bcb158d90ef4d14f75ef67f340943fc4149891dcce8f8b972a3" [[package]] name = "byteview" diff --git a/Cargo.toml b/Cargo.toml index bfbf958b..af19bb26 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,7 +46,7 @@ backtrace = "0.3" base64 = "0.21" blake2 = "0.10" bytes = "1.0" -bytesize = "1.1" +bytesize = "2.3" cfg-if = "1.0" chrono = { version = "0.4", features = ["serde"] } crc-fast = "1.6" diff --git a/src/garage/cli/remote/bucket.rs b/src/garage/cli/remote/bucket.rs index cd0ac87f..692ded63 100644 --- a/src/garage/cli/remote/bucket.rs +++ b/src/garage/cli/remote/bucket.rs @@ -437,8 +437,8 @@ impl Cli { let bs = bytesize::ByteSize::b(size); tab.push(format!( "Size:\t{} ({})", - bs.to_string_as(true), - bs.to_string_as(false) + bs.display().si(), + bs.display().iec() )); tab.push(format!("Size (exact):\t{}", size)); if !ver.blocks.is_empty() { @@ -488,11 +488,7 @@ fn print_bucket_info(bucket: &GetBucketInfoResponse) { String::new(), { let size = bytesize::ByteSize::b(bucket.bytes as u64); - format!( - "Size:\t{} ({})", - size.to_string_as(true), - size.to_string_as(false) - ) + format!("Size:\t{} ({})", size.display().si(), size.display().iec()) }, format!("Objects:\t{}", bucket.objects), ]; @@ -509,8 +505,8 @@ fn print_bucket_info(bucket: &GetBucketInfoResponse) { bytesize::ByteSize::b(bucket.unfinished_multipart_upload_bytes as u64); format!( "Size of unfinished multipart uploads:\t{} ({})", - mpu_size.to_string_as(true), - mpu_size.to_string_as(false), + mpu_size.display().si(), + mpu_size.display().iec(), ) }, ]); @@ -538,8 +534,8 @@ fn print_bucket_info(bucket: &GetBucketInfoResponse) { let ms = bytesize::ByteSize::b(ms); info.push(format!( " maximum size:\t{} ({})", - ms.to_string_as(true), - ms.to_string_as(false) + ms.display().si(), + ms.display().iec() )); } if let Some(mo) = bucket.quotas.max_objects { diff --git a/src/garage/cli/remote/layout.rs b/src/garage/cli/remote/layout.rs index edf92efc..fe0e3713 100644 --- a/src/garage/cli/remote/layout.rs +++ b/src/garage/cli/remote/layout.rs @@ -313,7 +313,7 @@ To know the correct value of the new layout version, invoke `garage layout show` pub fn capacity_string(v: Option) -> String { match v { - Some(c) => ByteSize::b(c).to_string_as(false), + Some(c) => ByteSize::b(c).display().iec().to_string(), None => "gateway".to_string(), } } @@ -383,7 +383,7 @@ pub fn print_cluster_layout(layout: &GetClusterLayoutResponse, empty_msg: &str) tags, role.zone, capacity_string(role.capacity), - ByteSize::b(usable_capacity).to_string_as(false), + ByteSize::b(usable_capacity).display().iec(), (100.0 * usable_capacity as f32) / (capacity as f32) )); } else { diff --git a/src/rpc/layout/mod.rs b/src/rpc/layout/mod.rs index d18c603d..702bd681 100644 --- a/src/rpc/layout/mod.rs +++ b/src/rpc/layout/mod.rs @@ -385,7 +385,7 @@ impl Crdt for LayoutStaging { impl NodeRole { pub fn capacity_string(&self) -> String { match self.capacity { - Some(c) => ByteSize::b(c).to_string_as(false), + Some(c) => ByteSize::b(c).display().iec().to_string(), None => "gateway".to_string(), } } diff --git a/src/rpc/layout/version.rs b/src/rpc/layout/version.rs index f307f86b..80a83145 100644 --- a/src/rpc/layout/version.rs +++ b/src/rpc/layout/version.rs @@ -359,13 +359,13 @@ impl LayoutVersion { if old_assignment_opt.is_some() { msg.push(format!( "Optimal partition size: {} ({} in previous layout)", - ByteSize::b(partition_size).to_string_as(false), - ByteSize::b(self.partition_size).to_string_as(false) + ByteSize::b(partition_size).display().iec(), + ByteSize::b(self.partition_size).display().iec() )); } else { msg.push(format!( "Optimal partition size: {}", - ByteSize::b(partition_size).to_string_as(false) + ByteSize::b(partition_size).display().iec() )); } // We write the partition size. @@ -722,14 +722,16 @@ impl LayoutVersion { let percent_cap = 100.0 * (used_cap as f32) / (total_cap as f32); msg.push(format!( "Usable capacity / total cluster capacity: {} / {} ({:.1} %)", - ByteSize::b(used_cap).to_string_as(false), - ByteSize::b(total_cap).to_string_as(false), + ByteSize::b(used_cap).display().iec(), + ByteSize::b(total_cap).display().iec(), percent_cap )); msg.push(format!( "Effective capacity (replication factor {}): {}", self.replication_factor, - ByteSize::b(used_cap / self.replication_factor as u64).to_string_as(false) + ByteSize::b(used_cap / self.replication_factor as u64) + .display() + .iec() )); if percent_cap < 80. { msg.push("".into()); @@ -838,8 +840,8 @@ impl LayoutVersion { tags_n, stored_partitions[*n], new_partitions[*n], - ByteSize::b(total_cap_n).to_string_as(false), - ByteSize::b(available_cap_n).to_string_as(false), + ByteSize::b(total_cap_n).display().iec(), + ByteSize::b(available_cap_n).display().iec(), (available_cap_n as f32) / (total_cap_n as f32) * 100.0, )); } @@ -849,8 +851,8 @@ impl LayoutVersion { replicated_partitions, stored_partitions_zone[z], //new_partitions_zone[z], - ByteSize::b(total_cap_z).to_string_as(false), - ByteSize::b(available_cap_z).to_string_as(false), + ByteSize::b(total_cap_z).display().iec(), + ByteSize::b(available_cap_z).display().iec(), percent_cap_z )); table.push("".into());