From 1cdfe8db2749a050a697acb36df74d955106e9ac Mon Sep 17 00:00:00 2001 From: Oliver Jowett Date: Wed, 10 Dec 2014 21:20:31 +0000 Subject: [PATCH] Rearrange validation so that the user only ever sees errors *after* providing input. In particular if the existing config does not validate then we should just ensure that the problematic question is displayed without a confusing error message beforehand; the error should only appear if the newly entered response doesn't validate. --- debian/dump1090-mutability.config | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/debian/dump1090-mutability.config b/debian/dump1090-mutability.config index 74e49fe..48df016 100644 --- a/debian/dump1090-mutability.config +++ b/debian/dump1090-mutability.config @@ -62,28 +62,32 @@ db_input_verify() { db_input $PRI $KEY; RESULT=$? db_go set -e + ASKED=0 while : do db_get $KEY if $VERIFY $RET; then return 0; fi if [ $RESULT -ne 0 ]; then # db_input failed, and the existing value does not validate - if [ $RESULT = 30 ] && [ $PRI != high ] + if [ $RESULT = 30 ] && [ $ASKED = 0 ] then - # question wasn't displayed, but existing value is invalid - # bump priority and try again - PRI=high + # question was skipped, but existing value is invalid + # bump priority and try again (once) + PRI=high + ASKED=1 else # give up, use the default value db_reset $KEY return 0 fi + else + # db_input was OK, but the value did not verify. + # show an error message + db_input high dump1090-mutability/invalid-$VERIFY || true fi - # db_input was OK, but the value did not verify. - # display an error and try again. + # try again set +e - db_input high dump1090-mutability/invalid-$VERIFY db_fset $KEY seen false db_input high $KEY; RESULT=$? db_go