]> wolfpit.net Git - tool/Arch-pacman/.git/commitdiff
makepkg: use c-style for loops for integrity checks
authorDave Reisner <dreisner@archlinux.org>
Wed, 4 Sep 2013 00:03:04 +0000 (20:03 -0400)
committerAllan McRae <allan@archlinux.org>
Wed, 18 Sep 2013 04:28:03 +0000 (14:28 +1000)
These loops already maintain an independent loop counter, so cut out
the middle man. While this change doesn't necessarily require that we
drop support for sparse arrays, we do via this patch. A new lint check
is added in check_sanity to abort when a sparse array is encountered.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Signed-off-by: Allan McRae <allan@archlinux.org>
scripts/makepkg.sh.in

index 44d5335be4e46a487ce58b36d5132433ab2cef2d..c5f7671466cc019ae2812a286f7be286a87efdf8 100644 (file)
@@ -1145,12 +1145,11 @@ generate_checksums() {
                        exit 1 # $E_CONFIG_ERROR
                fi
 
-               local ct=0
-               local indentsz numsrc=${#source[@]}
+               local indentsz idx numsrc=${#source[@]}
                printf "%s%n" "${integ}sums=(" indentsz
 
-               local netfile
-               for netfile in "${source[@]}"; do
+               for (( idx = 0; idx < numsrc; i++ )); do
+                       local netfile=${source[idx]}
                        local proto sum
                        proto="$(get_protocol "$netfile")"
 
@@ -1171,10 +1170,10 @@ generate_checksums() {
                        esac
 
                        # indent checksum on lines after the first
-                       printf "%*s%s" $(( ct ? indentsz : 0 )) '' "'$sum'"
+                       printf "%*s%s" $(( idx ? indentsz : 0 )) '' "'$sum'"
 
                        # print a newline on lines before the last
-                       (( ++ct < numsrc )) && echo
+                       (( ++idx < numsrc )) && echo
                done
 
                echo ")"
@@ -1193,39 +1192,31 @@ check_checksums() {
                if (( ${#integrity_sums[@]} == ${#source[@]} )); then
                        msg "$(gettext "Validating source files with %s...")" "${integ}sums"
                        correlation=1
-                       local errors=0
-                       local idx=0
-                       local file
-                       for file in "${source[@]}"; do
-                               local found=1
-                               file="$(get_filename "$file")"
+                       local idx errors=0
+                       for (( idx = 0; idx < ${#source[*]}; idx++ )); do
+                               local file="$(get_filename "${source[idx]}")"
                                printf '    %s ... ' "$file" >&2
 
-                               if [[ ${integrity_sums[$idx]} = 'SKIP' ]]; then
+                               if [[ ${integrity_sums[idx]} = 'SKIP' ]]; then
                                        printf '%s\n' "$(gettext "Skipped")" >&2
-                                       idx=$((idx + 1))
                                        continue
                                fi
 
                                if ! file="$(get_filepath "$file")"; then
                                        printf '%s\n' "$(gettext "NOT FOUND")" >&2
                                        errors=1
-                                       found=0
+                                       continue
                                fi
 
-                               if (( $found )) ; then
-                                       local expectedsum="${integrity_sums[idx],,}"
-                                       local realsum="$(openssl dgst -${integ} "$file")"
-                                       realsum="${realsum##* }"
-                                       if [[ $expectedsum = "$realsum" ]]; then
-                                               printf '%s\n' "$(gettext "Passed")" >&2
-                                       else
-                                               printf '%s\n' "$(gettext "FAILED")" >&2
-                                               errors=1
-                                       fi
+                               local expectedsum="${integrity_sums[idx],,}"
+                               local realsum="$(openssl dgst -${integ} "$file")"
+                               realsum="${realsum##* }"
+                               if [[ $expectedsum = "$realsum" ]]; then
+                                       printf '%s\n' "$(gettext "Passed")" >&2
+                               else
+                                       printf '%s\n' "$(gettext "FAILED")" >&2
+                                       errors=1
                                fi
-
-                               idx=$((idx + 1))
                        done
 
                        if (( errors )); then
@@ -2261,6 +2252,12 @@ check_sanity() {
                fi
        done
 
+       local idx=("${!source[@]}")
+       if (( (idx[-1] + 1) != ${#source[*]} )); then
+               error "$(gettext "Sparse arrays are not allowed for source")"
+               ret=1
+       fi
+
        return $ret
 }