Variables that are only meaningful within the function they are declared in are
now prefixed by "local".

Signed-off-by: Andres P <[email protected]>
---
 scripts/makepkg.sh.in |   29 +++++++++++++++++++++--------
 1 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index cbc344d..07fc6d5 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -135,6 +135,9 @@ clean_up() {
        fi
 
        if (( ! EXIT_CODE && CLEANUP )); then
+               local pkg
+               local file
+               
                # If it's a clean exit and -c/--clean has been passed...
                msg "$(gettext "Cleaning up...")"
                rm -rf "$pkgdir" "$srcdir"
@@ -308,7 +311,7 @@ get_downloadclient() {
        for i in "${dlagen...@]}"; do
                local handler="${i%%::*}"
                if [[ $proto = $handler ]]; then
-                       agent="${i##*::}"
+                       local agent="${i##*::}"
                        break
                fi
        done
@@ -388,6 +391,7 @@ check_deps() {
        # Also, a non-zero return value is not unexpected and we are manually 
dealing them
        set +E
        local ret=0
+       local pmout
        pmout=$(run_pacman -T "$@") || ret=$?
        set -E 
        
@@ -655,7 +659,7 @@ extract_sources() {
        msg "$(gettext "Extracting Sources...")"
        local netfile
        for netfile in "${sour...@]}"; do
-               file=$(get_filename "$netfile")
+               local file=$(get_filename "$netfile")
                if in_array "$file" ${noextra...@]}; then
                        #skip source files in the noextract=() array
                        #  these are marked explicitly to NOT be extracted
@@ -731,7 +735,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
@@ -747,8 +751,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
@@ -803,6 +808,7 @@ run_build() {
 }
 
 run_package() {
+       local pkgfunc
        if [[ -z $1 ]]; then
                pkgfunc="package"
        else
@@ -936,6 +942,7 @@ write_pkginfo() {
        [[ $provides ]]   && printf "provides = %s\n"  "${provid...@]}"
        [[ $backup ]]     && printf "backup = %s\n"    "${back...@]}"
 
+       local it
        for it in "${packaging_optio...@]}"; do
                local ret="$(check_option $it)"
                if [[ $ret != "?" ]]; then
@@ -984,6 +991,7 @@ create_package() {
        cd "$pkgdir"
        msg "$(gettext "Creating package...")"
 
+       local nameofpkg
        if [[ -z $1 ]]; then
                nameofpkg="$pkgname"
        else
@@ -1019,6 +1027,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} ;;
@@ -1153,7 +1162,7 @@ install_package() {
                msg "$(gettext "Installing %s package group with %s -U...")" 
"$pkgbase" "$PACMAN"
        fi
 
-       local pkglist
+       local pkg pkglist
        for pkg in ${pkgna...@]}; do
                if [[ -f $PKGDEST/${pkg}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT} 
]]; then
                        pkglist+=" 
$PKGDEST/${pkg}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}"
@@ -1228,7 +1237,7 @@ check_sanity() {
 
        local optdepend
        for optdepend in "${optdepen...@]}"; do
-               pkg=${optdepend%%:*}
+               local pkg=${optdepend%%:*}
                if [[ ! $pkg =~ ^[[:alnum:]\>\<\=\.\+\_\-]*$ ]]; then
                        error "$(gettext "Invalid syntax for optdepend : 
'%s'")" "$optdepend"
                fi
@@ -1267,6 +1276,7 @@ check_sanity() {
                return 1
        fi
 
+       local pkg
        if (( ${#pkgna...@]} > 1 )); then
                for pkg in ${pkgna...@]}; do
                        if ! declare -f package_${pkg} >/dev/null; then
@@ -1373,15 +1383,17 @@ devel_update() {
 }
 
 backup_package_variables() {
+       local var
        for var in ${splitpkg_overrid...@]}; do
-               indirect="${var}_backup"
+               local indirect="${var}_backup"
                eval "${indirect}=(\"\${$v...@]}\")"
        done
 }
 
 restore_package_variables() {
+       local var
        for var in ${splitpkg_overrid...@]}; do
-               indirect="${var}_backup"
+               local indirect="${var}_backup"
                if [[ -n ${!indirect} ]]; then
                        eval "${var}=(\"\${$indire...@]}\")"
                else
@@ -1410,6 +1422,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


Reply via email to