These loops already maintain an independent loop counter, so cut out the middle man. An extra fix is needed to continue supporting sparse arrays which, while weird, are valid. Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- If we don't care about supporting sparse arrays, I can simply drop the final hunk off of this patch and adjust the commit message. Keeping support was simple enough that I felt compelled to offer it. Note, however, that removing support then causes makepkg to fail in cryptic ways when it does encounter a sparse array, e.g.: $ makepkg -g ... ==> Generating checksums for source files... md5sums=('SKIP' 'e99e9189aa2f6084ac28b8ddf605aeb8' 'fb37e34ea006c79be1c54cbb0f803414' ==> ERROR: Unable to find source file . Aborting... And if you're still lost, a sparse array could be constructed like this: source=('git://anongit.freedesktop.org/systemd/systemd.git' 'initcpio-hook-udev' 'initcpio-install-udev') source[5]='initcpio-install-systemd' md5sums=('SKIP' 'e99e9189aa2f6084ac28b8ddf605aeb8' 'fb37e34ea006c79be1c54cbb0f803414') md5sums[5]='fbea6190413f5e54a4d0784ca4a340e4' This is perhaps a contrived example, but it's valid, and today's makepkg handles it just fine. scripts/makepkg.sh.in | 48 +++++++++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index f92f658..3197e62 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -1145,12 +1145,11 @@ generate_checksums() { exit 1 # $E_CONFIG_ERROR fi - local ct=0 - local numsrc=${#source[@]} + local idx numsrc=${#source[@]} printf "%s" "${integ}sums=(" - 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 ? ${#integ} + 6 : 0 )) '' "'$sum'" + printf "%*s%s" $(( idx ? ${#integ} + 6 : 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 @@ -2798,6 +2789,9 @@ else BUILDFILE="$startdir/$BUILDFILE" fi source_safe "$BUILDFILE" + # rebuild source array to avoid problems with sparse arrays during + # checksum verification. + source=("${source[@]}") fi # set defaults if they weren't specified in buildfile -- 1.8.4