mirror of
https://github.com/tw93/Mole.git
synced 2026-03-22 20:15:07 +00:00
fix: use Base-10 sizes and mdls logical size to match macOS Finder
- Switch bytes_to_human (shell) and humanizeBytes (Go) from Base-2 (1024) to Base-10 (1000) to match Apple's storage calculation standard since Snow Leopard - Add proper decimal rounding instead of truncation - Use mdls kMDItemLogicalSize for .app bundles to avoid APFS clone file undercounting by du Fixes #511
This commit is contained in:
@@ -80,7 +80,7 @@ func humanizeBytes(size int64) string {
|
||||
if size < 0 {
|
||||
return "0 B"
|
||||
}
|
||||
const unit = 1024
|
||||
const unit = 1000
|
||||
if size < unit {
|
||||
return fmt.Sprintf("%d B", size)
|
||||
}
|
||||
@@ -90,7 +90,7 @@ func humanizeBytes(size int64) string {
|
||||
exp++
|
||||
}
|
||||
value := float64(size) / float64(div)
|
||||
return fmt.Sprintf("%.1f %cB", value, "KMGTPE"[exp])
|
||||
return fmt.Sprintf("%.1f %cB", value, "kMGTPE"[exp])
|
||||
}
|
||||
|
||||
func coloredProgressBar(value, maxValue int64, percent float64) string {
|
||||
|
||||
@@ -63,15 +63,15 @@ func TestHumanizeBytes(t *testing.T) {
|
||||
{-100, "0 B"},
|
||||
{0, "0 B"},
|
||||
{512, "512 B"},
|
||||
{1023, "1023 B"},
|
||||
{1024, "1.0 KB"},
|
||||
{1536, "1.5 KB"},
|
||||
{10240, "10.0 KB"},
|
||||
{1048576, "1.0 MB"},
|
||||
{1572864, "1.5 MB"},
|
||||
{1073741824, "1.0 GB"},
|
||||
{1099511627776, "1.0 TB"},
|
||||
{1125899906842624, "1.0 PB"},
|
||||
{999, "999 B"},
|
||||
{1000, "1.0 kB"},
|
||||
{1500, "1.5 kB"},
|
||||
{10000, "10.0 kB"},
|
||||
{1000000, "1.0 MB"},
|
||||
{1500000, "1.5 MB"},
|
||||
{1000000000, "1.0 GB"},
|
||||
{1000000000000, "1.0 TB"},
|
||||
{1000000000000000, "1.0 PB"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
||||
Reference in New Issue
Block a user