From 64809bb4d472eec37da6517b3db58891d948d313 Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 20 Jul 2026 05:48:16 +0200 Subject: [PATCH] feat: Support progress tracking for segmented downloads (#1309) --- src/install.sh | 2 +- src/progress.sh | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/install.sh b/src/install.sh index 1e937c3..ac96d5b 100644 --- a/src/install.sh +++ b/src/install.sh @@ -168,7 +168,7 @@ else OUTPUT="log" fi - /run/progress.sh "$PAT" "$SIZE" "$MSG ([P])..." "$OUTPUT" & + /run/progress.sh "$PAT" "$SIZE" "$MSG ([P])..." "$OUTPUT" 52428800 & { LC_ALL=C wget "$URL" -O "$PAT" --no-verbose --no-check-certificate \ diff --git a/src/progress.sh b/src/progress.sh index dfb7ab0..f3388f3 100644 --- a/src/progress.sh +++ b/src/progress.sh @@ -20,6 +20,7 @@ escape() { getBytes() { local path="$1" + local mode="$2" local bytes if [ ! -s "$path" ] && [ ! -d "$path" ]; then @@ -27,7 +28,11 @@ getBytes() { return 0 fi - bytes=$(du -sb "$path" 2>/dev/null | cut -f1) || bytes="0" + if [[ "$mode" == "allocated" ]]; then + bytes=$(du -sB1 -- "$path" 2>/dev/null | cut -f1) || bytes="0" + else + bytes=$(du -sb -- "$path" 2>/dev/null | cut -f1) || bytes="0" + fi echo "$bytes" return 0 @@ -70,7 +75,7 @@ printSizeProgress() { fi printed="Y" - next_bytes=$((next_bytes + 52428800)) + next_bytes=$((next_bytes + step_bytes)) done return 0 @@ -89,10 +94,17 @@ path="$1" total="$2" body=$(escape "$3") output="${4:-}" +step_bytes="${5:-52428800}" +mode="${6:-apparent}" + +if [[ ! "$step_bytes" =~ ^[1-9][0-9]*$ ]]; then + echo "Invalid progress interval: $step_bytes" >&2 + exit 2 +fi printed="N" next_percent=10 -next_bytes=52428800 +next_bytes="$step_bytes" trap finishLogProgress EXIT @@ -102,7 +114,7 @@ fi while true; do - bytes=$(getBytes "$path") + bytes=$(getBytes "$path" "$mode") if (( bytes > 4096 )); then if [ -z "$total" ] || [[ "$total" == "0" ]] || (( bytes > total )); then