1
0
mirror of https://github.com/tw93/Mole.git synced 2026-03-23 15:20:06 +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:
tw93
2026-02-28 10:02:34 +08:00
parent 646ff72a96
commit 1be71edc9d
4 changed files with 36 additions and 20 deletions

View File

@@ -503,6 +503,19 @@ get_path_size_kb() {
echo "0"
return
}
# For .app bundles, prefer mdls logical size as it matches Finder
# (APFS clone/sparse files make 'du' severely underreport apps like Xcode)
if [[ "$path" == *.app || "$path" == *.app/ ]]; then
local mdls_size
mdls_size=$(mdls -name kMDItemLogicalSize -raw "$path" 2> /dev/null || true)
if [[ "$mdls_size" =~ ^[0-9]+$ && "$mdls_size" -gt 0 ]]; then
# Return in KB
echo "$((mdls_size / 1024))"
return
fi
fi
local size
size=$(command du -skP "$path" 2> /dev/null | awk 'NR==1 {print $1; exit}' || true)