pacman-key: allow get_from to return a default value

Keep the non-zero return val to let the caller know that the key wasn't
found.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dave Reisner 2011-09-25 15:24:53 -04:00 committed by Dan McGee
parent b6ccae2d18
commit 507b01b912
1 changed files with 4 additions and 2 deletions

View File

@ -95,7 +95,8 @@ There is NO WARRANTY, to the extent permitted by law.\n")"
# read the config file "$1" which has key=value pairs, and return the key which
# matches "$2". the equals sign between pairs may be surrounded by any amount
# of whitespace.
# of whitespace. Optionally, "$3" can be specified which is the default value
# when no key is found.
get_from() {
while IFS='=' read -r key value; do
[[ -z $key || ${key:0:1} = '#' ]] && continue
@ -105,6 +106,7 @@ get_from() {
return 0
fi
done < "$1"
printf '%s\n' "$3"
return 1
}
@ -437,7 +439,7 @@ fi
# if PACMAN_KEYRING_DIR isn't assigned, try to get it from the config
# file, falling back on a hard default
PACMAN_KEYRING_DIR=${PACMAN_KEYRING_DIR:-$(get_from "$CONFIG" "GPGDir" || echo "@sysconfdir@/pacman.d/gnupg")}
PACMAN_KEYRING_DIR=${PACMAN_KEYRING_DIR:-$(get_from "$CONFIG" "GPGDir" "@sysconfdir@/pacman.d/gnupg")}
GPG_PACMAN=(gpg --homedir ${PACMAN_KEYRING_DIR} --no-permission-warning)
if [[ -n ${KEYSERVER} ]]; then