makepkg: break out checksum generation to its own function
This also fixes a "bug" in which a PKGBUILD without any source array would generate "md5sums=()". While not technically wrong, we can easily do better and emit nothing at all.
This commit is contained in:
parent
a3d7230e4d
commit
51353edc61
1 changed files with 41 additions and 32 deletions
|
@ -1119,32 +1119,16 @@ get_integlist() {
|
|||
fi
|
||||
}
|
||||
|
||||
generate_checksums() {
|
||||
msg "$(gettext "Generating checksums for source files...")"
|
||||
generate_one_checksum() {
|
||||
local integ=$1 numsrc=${#source[*]} indentsz idx
|
||||
|
||||
if ! type -p openssl >/dev/null; then
|
||||
error "$(gettext "Cannot find the %s binary required for generating sourcefile checksums.")" "openssl"
|
||||
exit 1 # $E_MISSING_PROGRAM
|
||||
if (( numsrc == 0 )); then
|
||||
return
|
||||
fi
|
||||
|
||||
local integlist
|
||||
if (( $# == 0 )); then
|
||||
IFS=$'\n' read -rd '' -a integlist < <(get_integlist)
|
||||
else
|
||||
integlist=("$@")
|
||||
fi
|
||||
printf "%ssums=(%n" "$integ" indentsz
|
||||
|
||||
local integ
|
||||
for integ in "${integlist[@]}"; do
|
||||
if ! in_array "$integ" "${known_hash_algos[@]}"; then
|
||||
error "$(gettext "Invalid integrity algorithm '%s' specified.")" "$integ"
|
||||
exit 1 # $E_CONFIG_ERROR
|
||||
fi
|
||||
|
||||
local indentsz idx numsrc=${#source[@]}
|
||||
printf "%s%n" "${integ}sums=(" indentsz
|
||||
|
||||
for (( idx = 0; idx < numsrc; i++ )); do
|
||||
for (( idx = 0; idx < numsrc; ++idx )); do
|
||||
local netfile=${source[idx]}
|
||||
local proto sum
|
||||
proto="$(get_protocol "$netfile")"
|
||||
|
@ -1169,10 +1153,35 @@ generate_checksums() {
|
|||
printf "%*s%s" $(( idx ? indentsz : 0 )) '' "'$sum'"
|
||||
|
||||
# print a newline on lines before the last
|
||||
(( ++idx < numsrc )) && echo
|
||||
(( idx < (numsrc - 1) )) && echo
|
||||
done
|
||||
|
||||
echo ")"
|
||||
}
|
||||
|
||||
generate_checksums() {
|
||||
msg "$(gettext "Generating checksums for source files...")"
|
||||
|
||||
if ! type -p openssl >/dev/null; then
|
||||
error "$(gettext "Cannot find the %s binary required for generating sourcefile checksums.")" "openssl"
|
||||
exit 1 # $E_MISSING_PROGRAM
|
||||
fi
|
||||
|
||||
local integlist
|
||||
if (( $# == 0 )); then
|
||||
IFS=$'\n' read -rd '' -a integlist < <(get_integlist)
|
||||
else
|
||||
integlist=("$@")
|
||||
fi
|
||||
|
||||
local integ
|
||||
for integ in "${integlist[@]}"; do
|
||||
if ! in_array "$integ" "${known_hash_algos[@]}"; then
|
||||
error "$(gettext "Invalid integrity algorithm '%s' specified.")" "$integ"
|
||||
exit 1 # $E_CONFIG_ERROR
|
||||
fi
|
||||
|
||||
generate_one_checksum "$integ"
|
||||
done
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue