libmakepkg/srcinfo.sh: fix missing extglob in srcinfo_write_attr

We use an extended glob here, but were relying on having it globally set
in makepkg. This causes it to fail when used in scripts.

Since scripts using libmakepkg may not want extglob to be set, save and
restore the environment while explicitly setting extglob only where we
need it.

Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
This commit is contained in:
Levente Polyak 2024-02-28 21:18:42 +01:00
parent f343db5b8e
commit 016fd2633e
No known key found for this signature in database
GPG key ID: FC1B547C8D8172C8

View file

@ -40,11 +40,17 @@ srcinfo_write_attr() {
local attrname=$1 attrvalues=("${@:2}") local attrname=$1 attrvalues=("${@:2}")
# this function requires extglob - save current status to restore later
local shellopts=$(shopt -p extglob)
shopt -s extglob
# normalize whitespace, strip leading and trailing # normalize whitespace, strip leading and trailing
attrvalues=("${attrvalues[@]//+([[:space:]])/ }") attrvalues=("${attrvalues[@]//+([[:space:]])/ }")
attrvalues=("${attrvalues[@]#[[:space:]]}") attrvalues=("${attrvalues[@]#[[:space:]]}")
attrvalues=("${attrvalues[@]%[[:space:]]}") attrvalues=("${attrvalues[@]%[[:space:]]}")
eval "$shellopts"
printf "\t$attrname = %s\n" "${attrvalues[@]}" printf "\t$attrname = %s\n" "${attrvalues[@]}"
} }