summaryrefslogtreecommitdiffstats
path: root/scripts/libmakepkg/util
diff options
context:
space:
mode:
authorAllan McRae <allan@archlinux.org>2016-02-07 12:27:31 +0100
committerAllan McRae <allan@archlinux.org>2016-02-20 05:01:53 +0100
commit3cb1669e07106e9108976a76b7d2f37e659bce6c (patch)
tree49a88fefd123ee8e892c305e41e1c7b6981db298 /scripts/libmakepkg/util
parent0fa695d0e3862bf343804892c51d3793dd90be60 (diff)
downloadpacman-3cb1669e07106e9108976a76b7d2f37e659bce6c.tar.gz
pacman-3cb1669e07106e9108976a76b7d2f37e659bce6c.tar.xz
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>
Diffstat (limited to 'scripts/libmakepkg/util')
-rw-r--r--scripts/libmakepkg/util/util.sh17
1 files changed, 17 insertions, 0 deletions
diff --git a/scripts/libmakepkg/util/util.sh b/scripts/libmakepkg/util/util.sh
index 3c996dac..675e75de 100644
--- a/scripts/libmakepkg/util/util.sh
+++ b/scripts/libmakepkg/util/util.sh
@@ -37,6 +37,23 @@ in_array() {
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_path() {
local path="$1";