repo-add: only update database if entire command succeeded

It is not hard to think of situations where the repo database should not
be updated unless the whole operation succeeds.  Error out before a partial
database update occurs.

Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Allan McRae 2015-03-15 16:32:56 +10:00
parent d2cb52de12
commit 81d233b793

View file

@ -688,7 +688,6 @@ trap 'trap_exit "$(gettext "Aborted by user! Exiting...")"' INT
trap 'trap_exit "$(gettext "An unknown error has occurred. Exiting...")"' ERR trap 'trap_exit "$(gettext "An unknown error has occurred. Exiting...")"' ERR
declare -a args declare -a args
success=0
# parse arguments # parse arguments
while (( $# )); do while (( $# )); do
case $1 in case $1 in
@ -737,15 +736,16 @@ if (( SIGN || KEY || VERIFY )); then
check_gpg check_gpg
fi fi
fail=0
for arg in "${args[@]:1}"; do for arg in "${args[@]:1}"; do
case $cmd in case $cmd in
repo-add) add "$arg" ;; repo-add) add "$arg" ;;
repo-remove) remove "$arg" ;; repo-remove) remove "$arg" ;;
esac && success=1 esac || fail=1
done done
# if at least one operation was a success, re-zip database # if the whole operation was a success, re-zip and rotate database
if (( success )); then if (( !fail )); then
msg "$(gettext "Creating updated database file '%s'")" "$REPO_DB_FILE" msg "$(gettext "Creating updated database file '%s'")" "$REPO_DB_FILE"
create_db create_db
rotate_db rotate_db