From 0e67286599f4daa287b7b5399f171aa5f9098676 Mon Sep 17 00:00:00 2001 From: Kroese Date: Wed, 8 Jul 2026 23:55:02 +0200 Subject: [PATCH] fix: Improve file handling (#1242) --- src/progress.sh | 4 ++-- src/socket.sh | 2 +- src/utils.sh | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/progress.sh b/src/progress.sh index 24d0e8f..c46e1f0 100644 --- a/src/progress.sh +++ b/src/progress.sh @@ -27,12 +27,12 @@ do if [ ! -s "$path" ] && [ ! -d "$path" ]; then bytes="0" else - bytes=$(du -sb "$path" | cut -f1) + bytes=$(du -sb "$path" 2>/dev/null | cut -f1) || bytes="0" fi if (( bytes > 4096 )); then if [ -z "$total" ] || [[ "$total" == "0" ]] || [ "$bytes" -gt "$total" ]; then - size=$(numfmt --to=iec --suffix=B "$bytes" | sed -r 's/([A-Z])/ \1/') + size=$(numfmt --to=iec --suffix=B "$bytes" | sed -r 's/([A-Z])/ \1/') || size="${bytes} bytes" else size="$(echo "$bytes" "$total" | awk '{printf "%.1f", $1 * 100 / $2}')" size="$size%" diff --git a/src/socket.sh b/src/socket.sh index 5a4007c..8bda7ad 100644 --- a/src/socket.sh +++ b/src/socket.sh @@ -9,7 +9,7 @@ refresh() { [ ! -f "$path" ] && return 0 [ ! -s "$path" ] && return 0 - msg=$(< "$path") + msg=$(< "$path") || return 0 msg="${msg%$'\n'}" [ -z "$msg" ] && return 0 diff --git a/src/utils.sh b/src/utils.sh index f0b6488..2324a72 100644 --- a/src/utils.sh +++ b/src/utils.sh @@ -188,8 +188,8 @@ setOwner() { [ ! -f "$file" ] && return 1 dir=$(dirname -- "$file") - uid=$(stat -c '%u' "$dir") - gid=$(stat -c '%g' "$dir") + uid=$(stat -c '%u' "$dir") || return 1 + gid=$(stat -c '%g' "$dir") || return 1 ! chown "$uid:$gid" "$file" && return 1 @@ -204,8 +204,8 @@ makeDir() { ! mkdir -p "$path" && return 1 dir=$(dirname -- "$path") - uid=$(stat -c '%u' "$dir") - gid=$(stat -c '%g' "$dir") + uid=$(stat -c '%u' "$dir") || return 1 + gid=$(stat -c '%g' "$dir") || return 1 ! chown "$uid:$gid" "$path" && return 1 @@ -247,8 +247,8 @@ html() { HTML="${HTML/\[4\]/$footer}" HTML="${HTML/\[5\]/$FOOTER2}" - echo "$HTML" > "$PAGE" - echo "$body" > "$INFO" + echo "$HTML" > "$PAGE" || return 1 + echo "$body" > "$INFO" || return 1 return 0 }