1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-04 15:04:42 +00:00

fix: Improve shell script robustness by adding variable validation and safer du output parsing.

This commit is contained in:
Tw93
2025-12-30 18:07:48 +08:00
parent fcde129d2f
commit bb49ec3170
4 changed files with 14 additions and 7 deletions

View File

@@ -269,7 +269,7 @@ get_path_size_kb() {
# Use || echo 0 to ensure failure in du (e.g. permission error) doesn't exit script under set -e
# Pipefail would normally cause the pipeline to fail if du fails, but || handle catches it.
local size
size=$(command du -sk "$path" 2> /dev/null | awk '{print $1}' || true)
size=$(command du -sk "$path" 2> /dev/null | awk 'NR==1 {print $1; exit}' || true)
# Ensure size is a valid number (fix for non-numeric du output)
if [[ "$size" =~ ^[0-9]+$ ]]; then