libmakepkg: increase robustness of the detection of array variables
Extract array detection into its own utility function that ensures extglob is enabled. Suggested-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
0fa695d0e3
commit
3cb1669e07
2 changed files with 20 additions and 3 deletions
|
@ -43,7 +43,7 @@ lint_variable() {
|
||||||
for i in ${array[@]} ${arch_array[@]}; do
|
for i in ${array[@]} ${arch_array[@]}; do
|
||||||
eval "keys=(\"\${!$i[@]}\")"
|
eval "keys=(\"\${!$i[@]}\")"
|
||||||
if (( ${#keys[*]} > 0 )); then
|
if (( ${#keys[*]} > 0 )); then
|
||||||
if [[ "$(declare -p $i)" != "declare -a "* ]]; then
|
if ! is_array $i; then
|
||||||
error "$(gettext "%s should be an array")" "$i"
|
error "$(gettext "%s should be an array")" "$i"
|
||||||
ret=1
|
ret=1
|
||||||
fi
|
fi
|
||||||
|
@ -57,7 +57,7 @@ lint_variable() {
|
||||||
v="${i}_${a}"
|
v="${i}_${a}"
|
||||||
eval "keys=(\"\${!${v}[@]}\")"
|
eval "keys=(\"\${!${v}[@]}\")"
|
||||||
if (( ${#keys[*]} > 0 )); then
|
if (( ${#keys[*]} > 0 )); then
|
||||||
if [[ "$(declare -p $v)" != "declare -a "* ]]; then
|
if ! is_array $v; then
|
||||||
error "$(gettext "%s_%s should be an array")" "$i" "$a"
|
error "$(gettext "%s_%s should be an array")" "$i" "$a"
|
||||||
ret=1
|
ret=1
|
||||||
fi
|
fi
|
||||||
|
@ -68,7 +68,7 @@ lint_variable() {
|
||||||
for i in ${string[@]}; do
|
for i in ${string[@]}; do
|
||||||
eval "keys=(\"\${!$i[@]}\")"
|
eval "keys=(\"\${!$i[@]}\")"
|
||||||
if (( ${#keys[*]} > 0 )); then
|
if (( ${#keys[*]} > 0 )); then
|
||||||
if [[ "$(declare -p $i)" == "declare -a "* ]]; then
|
if is_array $i; then
|
||||||
error "$(gettext "%s should not be an array")" "$i"
|
error "$(gettext "%s should not be an array")" "$i"
|
||||||
ret=1
|
ret=1
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -37,6 +37,23 @@ in_array() {
|
||||||
return 1 # Not Found
|
return 1 # Not Found
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# tests if a variable is an array
|
||||||
|
is_array() {
|
||||||
|
local v=$1
|
||||||
|
local ret=1
|
||||||
|
|
||||||
|
# this function requires extglob - save current options to restore later
|
||||||
|
local shellopts=$(shopt -p)
|
||||||
|
shopt -s extglob
|
||||||
|
|
||||||
|
if [[ $(declare -p "$i") == declare\ -*([[:alnum:]])a*([[:alnum:]])\ * ]]; then
|
||||||
|
ret=0
|
||||||
|
fi
|
||||||
|
|
||||||
|
eval "$shellopts"
|
||||||
|
return $ret
|
||||||
|
}
|
||||||
|
|
||||||
# Canonicalize a directory path if it exists
|
# Canonicalize a directory path if it exists
|
||||||
canonicalize_path() {
|
canonicalize_path() {
|
||||||
local path="$1";
|
local path="$1";
|
||||||
|
|
Loading…
Add table
Reference in a new issue