refactor: replace associative array with Bash 3.2 compatible key-value store for collected runner data

This commit is contained in:
S
2026-03-01 08:45:13 -05:00
parent a34cc69681
commit 5bdf72063e

View File

@@ -227,7 +227,7 @@ ensure_runner_section() {
save_runner_field() {
local section="$1" key="$2" value="$3"
ini_set "$RUNNERS_CONF" "$section" "$key" "$value"
COLLECTED_DATA["${section}:${key}"]="$value"
_cdata_set "${section}:${key}" "$value"
}
# ===========================================================================
@@ -272,7 +272,32 @@ TOTAL_PROMPTS=$((runner_count * 11))
# ---------------------------------------------------------------------------
# Keep arrays for end-of-run summary; values are persisted immediately.
COLLECTED_NAMES=()
declare -A COLLECTED_DATA # COLLECTED_DATA["name:key"] = value
# Bash 3.2 compatible key-value store (no associative arrays)
_CDATA_KEYS=()
_CDATA_VALS=()
_cdata_set() {
local k="$1" v="$2" i
for i in "${!_CDATA_KEYS[@]}"; do
if [[ "${_CDATA_KEYS[$i]}" == "$k" ]]; then
_CDATA_VALS[i]="$v"
return 0
fi
done
_CDATA_KEYS+=("$k")
_CDATA_VALS+=("$v")
}
_cdata_get() {
local k="$1" default="${2:-}" i
for i in "${!_CDATA_KEYS[@]}"; do
if [[ "${_CDATA_KEYS[$i]}" == "$k" ]]; then
printf '%s' "${_CDATA_VALS[$i]}"
return 0
fi
done
printf '%s' "$default"
}
init_runners_conf
@@ -495,13 +520,13 @@ printf '%-20s %-10s %-8s %-6s %-10s %-6s %-10s %-24s\n' "----" "----" "----" "--
for r_name in "${COLLECTED_NAMES[@]}"; do
printf '%-20s %-10s %-8s %-6s %-10s %-6s %-10s %-24s\n' \
"$r_name" \
"${COLLECTED_DATA["${r_name}:host"]:-}" \
"${COLLECTED_DATA["${r_name}:type"]:-}" \
"${COLLECTED_DATA["${r_name}:boot"]:-}" \
"${COLLECTED_DATA["${r_name}:labels"]:-}" \
"${COLLECTED_DATA["${r_name}:capacity"]:-}" \
"${COLLECTED_DATA["${r_name}:repos"]:-}" \
"${COLLECTED_DATA["${r_name}:data_path"]:-}"
"$(_cdata_get "${r_name}:host")" \
"$(_cdata_get "${r_name}:type")" \
"$(_cdata_get "${r_name}:boot" "—")" \
"$(_cdata_get "${r_name}:labels")" \
"$(_cdata_get "${r_name}:capacity")" \
"$(_cdata_get "${r_name}:repos")" \
"$(_cdata_get "${r_name}:data_path")"
done
printf '\n Saved to: %s\n\n' "$RUNNERS_CONF"