From 2feb0388bb3b38a49d2e4de3099edd5fc63785cc Mon Sep 17 00:00:00 2001 From: Parth Jadhav Date: Sat, 24 Oct 2026 00:31:53 +0530 Subject: [PATCH] Show sizes that round to 1000 MB in GB Term.size checked for 1 GB before rounding, so 999,999,999 bytes came out as "1000 MB". Anything from 999.5 MB up now takes the GB branch and shows "1.0 GB", with a selftest check covering the boundary on both sides. Fixes #73. --- Sources/removemacai/SelfTest.swift | 3 +++ Sources/removemacai/Term.swift | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Sources/removemacai/SelfTest.swift b/Sources/removemacai/SelfTest.swift index be84e30..e822c4e 100644 --- a/Sources/removemacai/SelfTest.swift +++ b/Sources/removemacai/SelfTest.swift @@ -257,6 +257,9 @@ func selfTest() -> Bool { check(!exited.ok && exited.output.contains("after-exit"), "a step that exits doesn't stop the rest") check(Shell.run("/bin/sh", ["-c", Shell.adminScript(["true", "true"])]).ok, "administrator steps succeed together") check(Term.pad("abc", 5) == "abc " && Term.pad("abcdef", 5) == "abcdef ", "columns never run together") + check(Term.size(999_999_999) == "1.0 GB" && Term.size(999_500_000) == "1.0 GB" + && Term.size(999_499_999) == "999 MB" && Term.size(1_000_000_000) == "1.0 GB" + && Term.size(5_000_000) == "5 MB", "sizes that round to 1000 MB are shown in GB") check(Storage.isAppleCache("/x/com.apple.Safari") && Storage.isAppleCache("/x/CloudKit") && Storage.isAppleCache("/x/GeoServices") && !Storage.isAppleCache("/x/Homebrew") && !Storage.isAppleCache("/x/com.google.Chrome"), "macOS caches without the com.apple. prefix are left alone") diff --git a/Sources/removemacai/Term.swift b/Sources/removemacai/Term.swift index 808767b..12419cd 100644 --- a/Sources/removemacai/Term.swift +++ b/Sources/removemacai/Term.swift @@ -16,7 +16,8 @@ enum Term { static func size(_ bytes: Int64) -> String { if bytes <= 0 { return "0 MB" } - if bytes >= 1_000_000_000 { return String(format: "%.1f GB", Double(bytes) / 1e9) } + // Anything that would round to "1000 MB" is shown in GB instead. + if bytes >= 999_500_000 { return String(format: "%.1f GB", Double(bytes) / 1e9) } return String(format: "%.0f MB", max(1, Double(bytes) / 1e6)) }