summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--HACKING/code-quality.md3
-rwxr-xr-xsrc/chroot-tools/librechroot16
2 files changed, 12 insertions, 7 deletions
diff --git a/HACKING/code-quality.md b/HACKING/code-quality.md
index a520ce5..8efd561 100644
--- a/HACKING/code-quality.md
+++ b/HACKING/code-quality.md
@@ -49,7 +49,8 @@ Use `set -u` if you can; it makes using an unset variable an error.
- If a variable not being set is valid (perhaps a configuration
option), use `${var:-}` when accessing it to suppress the error.
- An empty array counts as unset, so if you have an array that may be
- empty, use `set +u` before accessing it.
+ empty, use `${var+"${var[@]}"}` (don't put quotes around the outer
+ pair of braces) to only access it if it's non-empty.
- The reason for this is that a normal string variable is basically
an array with length=1; an unset variable looks like an array
with length=0. Weird stuff.
diff --git a/src/chroot-tools/librechroot b/src/chroot-tools/librechroot
index 5ff9c99..ba722c7 100755
--- a/src/chroot-tools/librechroot
+++ b/src/chroot-tools/librechroot
@@ -54,18 +54,22 @@ arch-nspawn() {
local copydir=$1; shift
local cmd=("$@")
- set +u # if an array is empty, it counts as unbound
- "$_arch_nspawn" "${arch_nspawn_flags[@]}" "$copydir" "${sysd_nspawn_flags[@]}" -- "${cmd[@]}"
- set -u
+ "$_arch_nspawn" \
+ ${arch_nspawn_flags+"${arch_nspawn_flags[@]}"} \
+ "$copydir" \
+ ${sysd_nspawn_flags+"${sysd_nspawn_flags[@]}"} \
+ -- \
+ "${cmd[@]}"
}
# Usage: mkarchroot $copydir $pkgs...
mkarchroot() {
local copydir=$1; shift
local pkgs=("$@")
- set +u # if an array is empty, it counts as unbound
- "$_mkarchroot" "${arch_nspawn_flags[@]}" "$copydir" "${pkgs[@]}"
- set -u
+ "$_mkarchroot" \
+ ${arch_nspawn_flags+"${arch_nspawn_flags[@]}"} \
+ "$copydir" \
+ "${pkgs[@]}"
}
# Usage: _makechrootpkg $function $arguments...