makepkg: use c-style for loops for integrity checks

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>
This commit is contained in:
Dave Reisner 2013-09-03 20:03:04 -04:00 committed by Allan McRae
parent de570d1a65
commit 9388808964
1 changed files with 24 additions and 27 deletions

View File

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