diff options
author | Dave Reisner <dreisner@archlinux.org> | 2014-08-07 04:01:41 +0200 |
---|---|---|
committer | Allan McRae <allan@archlinux.org> | 2014-09-30 04:56:21 +0200 |
commit | a3d7230e4dd85f5d7b9bd3877ae9ad4259fa71b0 (patch) | |
tree | f6f0756a7993faa7cfd98b3964e0639a52b9077a /scripts | |
parent | b52ed49d75ff77ef4f6ad2bef576184bda9b98d0 (diff) | |
download | pacman-a3d7230e4dd85f5d7b9bd3877ae9ad4259fa71b0.tar.gz pacman-a3d7230e4dd85f5d7b9bd3877ae9ad4259fa71b0.tar.xz |
makepkg: break out check_checksums to reasonably sized functions
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/makepkg.sh.in | 95 |
1 files changed, 54 insertions, 41 deletions
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 49f5e599..2b5171e4 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -1176,53 +1176,66 @@ generate_checksums() { done } -check_checksums() { - (( SKIPCHECKSUMS )) && return 0 - (( ! ${#source[@]} )) && return 0 +verify_integrity_one() { + local source_name=$1 integ=$2 expectedsum=$3 - local correlation=0 - local integ required - for integ in "${known_hash_algos[@]}"; do - local sumname="${integ}sums[@]" - local integrity_sums=("${!sumname}") - if (( ${#integrity_sums[@]} == ${#source[@]} )); then - msg "$(gettext "Validating source files with %s...")" "${integ}sums" - correlation=1 - 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 - printf '%s\n' "$(gettext "Skipped")" >&2 - continue - fi + local file="$(get_filename "$source_name")" + printf ' %s ... ' "$file" >&2 - if ! file="$(get_filepath "$file")"; then - printf '%s\n' "$(gettext "NOT FOUND")" >&2 - errors=1 - continue - fi + if [[ $expectedsum = 'SKIP' ]]; then + printf '%s\n' "$(gettext "Skipped")" >&2 + return + 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 - done + if ! file="$(get_filepath "$file")"; then + printf '%s\n' "$(gettext "NOT FOUND")" >&2 + return 1 + fi - if (( errors )); then - error "$(gettext "One or more files did not pass the validity check!")" - exit 1 # TODO: error code - fi - elif (( ${#integrity_sums[@]} )); then - error "$(gettext "Integrity checks (%s) differ in size from the source array.")" "$integ" + 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 + return 1 + fi + + return 0 +} + +verify_integrity_sums() { + local integ=$1 integrity_sums + + array_build integrity_sums "${integ}sums" + + if (( ${#integrity_sums[@]} == ${#source[@]} )); then + msg "$(gettext "Validating source files with %s...")" "${integ}sums" + local idx errors=0 + for (( idx = 0; idx < ${#source[*]}; idx++ )); do + verify_integrity_one "${source[idx]}" "$integ" "${integrity_sums[idx]}" || errors=1 + done + + if (( errors )); then + error "$(gettext "One or more files did not pass the validity check!")" exit 1 # TODO: error code fi + elif (( ${#integrity_sums[@]} )); then + error "$(gettext "Integrity checks (%s) differ in size from the source array.")" "$integ" + exit 1 # TODO: error code + else + return 1 + fi +} + +check_checksums() { + (( SKIPCHECKSUMS )) && return 0 + (( ! ${#source[@]} )) && return 0 + + local correlation=0 + local integ + for integ in "${known_hash_algos[@]}"; do + verify_integrity_sums "$integ" && correlation=1 done if (( ! correlation )); then |