[PATCH] libmakepkg/util/pkgbuild.sh: fix missing extglob

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] libmakepkg/util/pkgbuild.sh: fix missing extglob

Eli Schwartz-2
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: Eli Schwartz <[hidden email]>
---
 scripts/libmakepkg/util/pkgbuild.sh.in | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/scripts/libmakepkg/util/pkgbuild.sh.in b/scripts/libmakepkg/util/pkgbuild.sh.in
index 25ad03ce..d35c064b 100644
--- a/scripts/libmakepkg/util/pkgbuild.sh.in
+++ b/scripts/libmakepkg/util/pkgbuild.sh.in
@@ -80,6 +80,10 @@ extract_function_variable() {
  printf -v attr_regex '^[[:space:]]* %s\+?=[^(]' "$2"
  fi
 
+ # save our shell options and turn on extglob
+ local shellopts=$(shopt -p)
+ shopt -s extglob
+
  while read -r; do
  # strip leading whitespace and any usage of declare
  decl=${REPLY##*([[:space:]])}
@@ -89,6 +93,8 @@ extract_function_variable() {
  r=0
  done < <(grep_function "$funcname" "$attr_regex")
 
+ eval "$shellopts"
+
  return $r
 }
 
--
2.16.2
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] libmakepkg/util/pkgbuild.sh: fix missing extglob

Eli Schwartz-2
On 03/19/2018 11:05 PM, Eli Schwartz wrote:
> 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.

This was... fun to find. I was writing a minimal srcinfo generator tool
to replace mksrcinfo from pkgbuild-introspection, and along the way
discovered that the following did not work:

bash -c 'source /usr/share/makepkg/srcinfo.sh; source PKGBUILD;
write_srcinfo_content'

But running that in an interactive shell did work. Why? Well, because
*bash-completion* turns on extglob.

--
Eli Schwartz
Bug Wrangler and Trusted User


signature.asc (849 bytes) Download Attachment