From: Martin Schwenke Date: Thu, 7 Mar 2019 04:40:59 +0000 (+1100) Subject: ctdb-tests: Shell cleanups in wait_until() function X-Git-Tag: talloc-2.2.0~73 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6555fbce995d3d3a7b162ea49a4a9844e234fed8;p=thirdparty%2Fsamba.git ctdb-tests: Shell cleanups in wait_until() function This file is included by local_daemons.sh, which is not a bash script and wait_until() uses the "local" keyword. Prefixing variable names with '_' to indicate that they are local changes a lot of lines in this function. So, fix indentation, potential quoting problems and other ShellCheck hits while touching this function. Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- diff --git a/ctdb/tests/scripts/common.sh b/ctdb/tests/scripts/common.sh index c1713fa1f89..b75fe066dcd 100644 --- a/ctdb/tests/scripts/common.sh +++ b/ctdb/tests/scripts/common.sh @@ -29,43 +29,42 @@ fi # I is the recheck interval. wait_until () { - local timeout="$1" ; shift # "$@" is the command... + _timeout="$1" ; shift # "$@" is the command... - local interval=1 - case "$timeout" in + _interval=1 + case "$_timeout" in */*) - interval="${timeout#*/}" - timeout="${timeout%/*}" - esac - - local negate=false - if [ "$1" = "!" ] ; then - negate=true - shift - fi - - echo -n "<${timeout}|" - local t=$timeout - while [ $t -gt 0 ] ; do - local rc=0 - "$@" || rc=$? - if { ! $negate && [ $rc -eq 0 ] ; } || \ - { $negate && [ $rc -ne 0 ] ; } ; then - echo "|$(($timeout - $t))|" - echo "OK" - return 0 + _interval="${_timeout#*/}" + _timeout="${_timeout%/*}" + esac + + _negate=false + if [ "$1" = "!" ] ; then + _negate=true + shift fi - local i - for i in $(seq 1 $interval) ; do - echo -n . + + printf '<%d|' "$_timeout" + _t="$_timeout" + while [ "$_t" -gt 0 ] ; do + _rc=0 + "$@" || _rc=$? + if { ! $_negate && [ $_rc -eq 0 ] ; } || \ + { $_negate && [ $_rc -ne 0 ] ; } ; then + echo "|$((_timeout - _t))|" + echo "OK" + return 0 + fi + for _i in $(seq 1 "$_interval") ; do + printf '.' + done + _t=$((_t - _interval)) + sleep "$_interval" done - t=$(($t - $interval)) - sleep $interval - done - echo "*TIMEOUT*" + echo "*TIMEOUT*" - return 1 + return 1 } # setup_ctdb_base [item-to-copy]...