From d9c64b267540a7c0a62f219c1c27c790234fd11c Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Mon, 19 May 2025 19:24:43 +0100 Subject: xbmk: stricter handling of files on while loops i overlooked these! Signed-off-by: Leah Rowe --- include/lib.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/lib.sh') diff --git a/include/lib.sh b/include/lib.sh index 6c831795..025db88a 100644 --- a/include/lib.sh +++ b/include/lib.sh @@ -106,9 +106,9 @@ fx_() dx_() { - [ -f "$2" ] && while read -r fx; do + [ ! -f "$2" ] || while read -r fx; do $1 "$fx" || return 1 - done < "$2"; : + done < "$2" || err "dx_ $*: cannot read '$2'"; : } x_() -- cgit v1.2.1 From 8aaf404ddea8a8d6c21f0a1f83f1675a8b0895aa Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Mon, 19 May 2025 19:29:59 +0100 Subject: lib.sh: Use while, not for, to process arguments This is more reliable against globbing, in context of for. Signed-off-by: Leah Rowe --- include/lib.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'include/lib.sh') diff --git a/include/lib.sh b/include/lib.sh index 025db88a..184d0491 100644 --- a/include/lib.sh +++ b/include/lib.sh @@ -53,8 +53,10 @@ setvars() fi val="$1" shift 1 - for var in "$@"; do - _setvars="$var=\"$val\"; $_setvars" + while true; do + [ $# -lt 1 ] && break + _setvars="$1=\"$val\"; $_setvars" + shift 1 done printf "%s\n" "${_setvars% }" } @@ -69,9 +71,11 @@ setcfg() chkvars() { - for var in "$@"; do - eval "[ -n \"\${$var+x}\" ] || err \"$var unset\"" - eval "[ -n \"\$$var\" ] || err \"$var unset\"" + while true; do + [ $# -lt 1 ] && break + eval "[ -n \"\${$1+x}\" ] || err \"$1 unset\"" + eval "[ -n \"\$$1\" ] || err \"$1 unset\"" + shift 1 done; : } -- cgit v1.2.1 From 900da04efa929a9373d5a6f3f56f8b8ac8f193df Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Mon, 19 May 2025 19:57:06 +0100 Subject: tree.sh: fix up copy_elf(), bad for loop Because of how sh works, having just the [] line causes sh to exit, annoyingly without an error message, but it does cause a non-zero exit. This bug will have already been triggering, before I added the recent error handling on files for this for loop. also do it to the other loop in lib.sh Signed-off-by: Leah Rowe --- include/lib.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/lib.sh') diff --git a/include/lib.sh b/include/lib.sh index 184d0491..7c4d71ea 100644 --- a/include/lib.sh +++ b/include/lib.sh @@ -111,7 +111,7 @@ fx_() dx_() { [ ! -f "$2" ] || while read -r fx; do - $1 "$fx" || return 1 + $1 "$fx" || return 1; : done < "$2" || err "dx_ $*: cannot read '$2'"; : } -- cgit v1.2.1