[pacman-dev] [PATCH 05/11] makepkg: undeclared local variables

Andres P aepd87 at gmail.com
Thu Jun 17 08:44:45 EDT 2010


Tight variable scoping should avoid further regressions with new patches and
variable overriding (see what ac5c2fd09 fixed).

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

diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 37241bd..630d9c2 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -146,12 +146,14 @@ clean_up() {
 			if (( PKGFUNC )); then
 				rm -f "${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-package.log"*
 			elif (( SPLITPKG )); then
+				local pkg
 				for pkg in ${pkgname[@]}; do
 					rm -f "${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-package_${pkg}.log"*
 				done
 			fi
 
 			# clean up dangling symlinks to packages
+			local file
 			for pkg in ${pkgname[@]}; do
 				for file in ${pkg}-*-*-${CARCH}${PKGEXT}; do
 					if [[ -h $file && ! -e $file ]]; then
@@ -308,7 +310,7 @@ get_downloadclient() {
 	for i in "${DLAGENTS[@]}"; do
 		local handler="${i%%::*}"
 		if [[ $proto = $handler ]]; then
-			agent="${i##*::}"
+			local agent="${i##*::}"
 			break
 		fi
 	done
@@ -384,6 +386,9 @@ run_pacman() {
 check_deps() {
 	(( $# > 0 )) || return
 
+	# XXX: Due to a bash bug, pmout's subshell cannot be declared sensibly:
+	#      local pmout=$(run_pacman -T "$@")
+	local pmout
 	local ret=0
 	pmout=$(run_pacman -T "$@")
 	ret=$?
@@ -651,7 +656,7 @@ extract_sources() {
 	msg "$(gettext "Extracting Sources...")"
 	local netfile
 	for netfile in "${source[@]}"; do
-		file=$(get_filename "$netfile")
+		local file=$(get_filename "$netfile")
 		if in_array "$file" ${noextract[@]}; then
 			#skip source files in the noextract=() array
 			#  these are marked explicitly to NOT be extracted
@@ -727,7 +732,7 @@ run_function() {
 	if [[ -z $1 ]]; then
 		return 1
 	fi
-	pkgfunc="$1"
+	local pkgfunc="$1"
 
 	# clear user-specified makeflags if requested
 	if [[ $(check_option makeflags) = "n" ]]; then
@@ -743,8 +748,9 @@ run_function() {
 	local shellopts=$(shopt -p)
 
 	local ret=0
+	local restoretrap
 	if (( LOGGING )); then
-		BUILDLOG="${startdir}/${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-$pkgfunc.log"
+		local BUILDLOG="${startdir}/${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-$pkgfunc.log"
 		if [[ -f $BUILDLOG ]]; then
 			local i=1
 			while true; do
@@ -799,6 +805,7 @@ run_build() {
 }
 
 run_package() {
+	local pkgfunc
 	if [[ -z $1 ]]; then
 		pkgfunc="package"
 	else
@@ -932,6 +939,7 @@ write_pkginfo() {
 	[[ $provides ]]   && printf "provides = %s\n"  "${provides[@]}"
 	[[ $backup ]]     && printf "backup = %s\n"    "${backup[@]}"
 
+	local it
 	for it in "${packaging_options[@]}"; do
 		local ret="$(check_option $it)"
 		if [[ $ret != "?" ]]; then
@@ -980,6 +988,7 @@ create_package() {
 	cd "$pkgdir"
 	msg "$(gettext "Creating package...")"
 
+	local nameofpkg
 	if [[ -z $1 ]]; then
 		nameofpkg="$pkgname"
 	else
@@ -997,6 +1006,7 @@ create_package() {
 	local comp_files=".PKGINFO"
 
 	# check for changelog/install files
+	local i orig dest
 	for i in 'changelog' 'install'; do
 		orig="${!i}"
 		dest=".${i^^}"
@@ -1011,6 +1021,7 @@ create_package() {
 	# tar it up
 	msg2 "$(gettext "Compressing package...")"
 
+	local EXT
 	case "$PKGEXT" in
 		*tar.gz)  EXT=${PKGEXT%.gz} ;;
 		*tar.bz2) EXT=${PKGEXT%.bz2} ;;
@@ -1135,7 +1146,7 @@ install_package() {
 		msg "$(gettext "Installing %s package group with %s -U...")" "$pkgbase" "$PACMAN"
 	fi
 
-	local pkglist
+	local pkg pkglist
 	for pkg in ${pkgname[@]}; do
 		if [[ -f $PKGDEST/${pkg}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT} ]]; then
 			pkglist="${pkglist} $PKGDEST/${pkg}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}"
@@ -1215,7 +1226,7 @@ check_sanity() {
 
 	local optdepend
 	for optdepend in "${optdepends[@]}"; do
-		pkg=${optdepend%%:*}
+		local pkg=${optdepend%%:*}
 		if [[ ! $pkg =~ ^[[:alnum:]\>\<\=\.\+\_\-]*$ ]]; then
 			error "$(gettext "Invalid syntax for optdepend : '%s'")" "$optdepend"
 		fi
@@ -1360,15 +1371,17 @@ devel_update() {
 }
 
 backup_package_variables() {
+	local var
 	for var in ${splitpkg_overrides[@]}; do
-		indirect="${var}_backup"
+		local indirect="${var}_backup"
 		eval "${indirect}=(\"\${$var[@]}\")"
 	done
 }
 
 restore_package_variables() {
+	local var
 	for var in ${splitpkg_overrides[@]}; do
-		indirect="${var}_backup"
+		local indirect="${var}_backup"
 		if [[ -n ${!indirect} ]]; then
 			eval "${var}=(\"\${$indirect[@]}\")"
 		else
@@ -1383,6 +1396,7 @@ parse_options() {
 	local long_options=$1; shift;
 	local ret=0;
 	local unused_options=""
+	local i
 
 	while [[ -n $1 ]]; do
 		if [[ ${1:0:2} = '--' ]]; then
-- 
1.7.1



More information about the pacman-dev mailing list