[pacman-dev] [PATCH 1/3] makepkg: simplify su/sudo calling logic

Andres P aepd87 at gmail.com
Fri Jun 18 20:47:14 EDT 2010


* Before, calls to sudo were not being word-split, whereas falling back to su,
  for some reason, meant applying IFS to the arguments. From now on calling
  either does not mangle any of the operands.

* Instead of recreating the basic bash concept of $? with $ret, opt for
  stacking the command line into a variable that can later be checked *once*
  for a return code.

Signed-off-by: Andres P <aepd87 at gmail.com>
---
 scripts/makepkg.sh.in |   14 ++++++--------
 1 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 536da30..2258d2a 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -370,17 +370,15 @@ download_file() {
 }
 
 run_pacman() {
-	local ret=0
-	if (( ! ASROOT )) && [[ $1 != "-T" && $1 != "-Qq" ]]; then
-		if type -p sudo >/dev/null && sudo -l $PACMAN &>/dev/null; then
-			sudo $PACMAN $PACMAN_OPTS "$@" || ret=$?
+	local cmd=$(printf "%q " "$PACMAN" $PACMAN_OPTS "$@")
+	if (( ! ASROOT )) && [[ ! $1 =~ ^-(T|Qq)$ ]]; then
+		if type -p sudo >/dev/null && sudo -l "$PACMAN" &>/dev/null; then
+			cmd="sudo $cmd"
 		else
-			su -c "$PACMAN $PACMAN_OPTS $*" || ret=$?
+			cmd="su -c '$cmd'"
 		fi
-	else
-		$PACMAN $PACMAN_OPTS "$@" || ret=$?
 	fi
-	return $ret
+	eval "$cmd"
 }
 
 check_deps() {
-- 
1.7.1



More information about the pacman-dev mailing list