summaryrefslogtreecommitdiff
path: root/src/lib/bootstrap.source.sh
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-06-14 15:17:32 +0300
committerPaul Buetow <paul@buetow.org>2026-06-14 15:17:32 +0300
commit67231312ba2d80592e305b08bbf03f7aece2e4a3 (patch)
tree960a4cf09d741215b3d4c6a2fefbc8c52d09b0ac /src/lib/bootstrap.source.sh
parentaabe2efbb79938dbbdb4f0ab496cdc22e7280736 (diff)
lm0 de-duplicate imagemagick detection and config-array parsing
Introduce a shared resolve_config_array helper in bootstrap.source.sh that parses a config variable declared as either a Bash array or a whitespace-separated scalar into a named output array. resolve_tar_opts and resolve_sync_destinations now both delegate to it, with resolve_tar_opts keeping its "-c" default for the empty/unset case. validate_imagemagick now reuses resolve_imagemagick_command instead of duplicating the magick/convert probing, reporting failures through config_error so the validation output is unchanged. Add a print-config test covering the empty TAR_OPTS (scalar and array) fallback to the default. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'src/lib/bootstrap.source.sh')
-rw-r--r--src/lib/bootstrap.source.sh42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/lib/bootstrap.source.sh b/src/lib/bootstrap.source.sh
index 244cd55..67ba090 100644
--- a/src/lib/bootstrap.source.sh
+++ b/src/lib/bootstrap.source.sh
@@ -60,6 +60,48 @@ log_warning() {
printf 'WARNING: %s\n' "$*" >&2
}
+# Read a configuration value into the named array, accepting both Bash array
+# and whitespace-separated scalar declarations of the same variable.
+# This is shared by resolve_tar_opts and resolve_sync_destinations so the
+# "array or scalar config" parsing lives in exactly one place.
+#
+# Arguments:
+# $1 name of the source config variable (e.g. TAR_OPTS)
+# $2 name of the destination array variable (nameref)
+# Returns:
+# 0 if the variable was declared (the destination may still be empty),
+# 1 if the variable was not declared at all (lets callers apply defaults).
+resolve_config_array() {
+ local -r config_var="$1"; shift
+ local -n config_array_ref="$1"; shift
+ local config_decl
+
+ config_array_ref=()
+
+ # declare -p fails when the variable was never set; callers use the
+ # non-zero return to distinguish "unset" from "set but empty".
+ if ! config_decl=$(declare -p "$config_var" 2>/dev/null); then
+ return 1
+ fi
+
+ case "$config_decl" in
+ declare\ -a*\ "$config_var"=*)
+ # Already a real array: copy it element by element.
+ local -n config_source_ref="$config_var"
+ # shellcheck disable=SC2034
+ config_array_ref=("${config_source_ref[@]}")
+ ;;
+ *)
+ # Scalar string: word-split it into the destination array.
+ local -n config_scalar_ref="$config_var"
+ if [ -n "${config_scalar_ref:-}" ]; then
+ # shellcheck disable=SC2034
+ read -r -a config_array_ref <<< "$config_scalar_ref"
+ fi
+ ;;
+ esac
+}
+
resolve_default_rc_file() {
local source_root