fix: follow symlinks when calculating model disk usage
HuggingFace models use symlinks pointing to blobs in the cache. The stat command was returning the size of the symlink itself (76 bytes) instead of the actual file it points to. Fixed by: - Adding -L flag to stat commands to follow symlinks - Testing which stat format works (Linux -c vs macOS -f) before executing - Using proper spacing and quotes in stat commands - Checking for both regular files and symlinks in the condition This fixes disk usage showing as 1 KB instead of the actual ~50+ GB for models like FLUX.
This commit is contained in:
@@ -607,9 +607,17 @@ get_model_disk_usage() {
|
|||||||
|
|
||||||
local total_bytes=0
|
local total_bytes=0
|
||||||
while IFS= read -r file_path; do
|
while IFS= read -r file_path; do
|
||||||
if [[ -f "$file_path" ]]; then
|
if [[ -f "$file_path" ]] || [[ -L "$file_path" ]]; then
|
||||||
local file_size
|
local file_size
|
||||||
file_size=$(stat -f%z "$file_path" 2>/dev/null || stat -c%s "$file_path" 2>/dev/null || echo "0")
|
# Use -L to follow symlinks (HuggingFace uses symlinks to blobs)
|
||||||
|
# Try Linux stat first, then macOS stat
|
||||||
|
if stat -L -c "%s" "$file_path" >/dev/null 2>&1; then
|
||||||
|
file_size=$(stat -L -c "%s" "$file_path" 2>/dev/null)
|
||||||
|
elif stat -L -f "%z" "$file_path" >/dev/null 2>&1; then
|
||||||
|
file_size=$(stat -L -f "%z" "$file_path" 2>/dev/null)
|
||||||
|
else
|
||||||
|
file_size=0
|
||||||
|
fi
|
||||||
total_bytes=$((total_bytes + file_size))
|
total_bytes=$((total_bytes + file_size))
|
||||||
fi
|
fi
|
||||||
done <<< "$model_files"
|
done <<< "$model_files"
|
||||||
|
|||||||
Reference in New Issue
Block a user