ctdb-tests: Shell cleanups in wait_until() function
authorMartin Schwenke <martin@meltin.net>
Thu, 7 Mar 2019 04:40:59 +0000 (15:40 +1100)
committerAmitay Isaacs <amitay@samba.org>
Fri, 15 Mar 2019 05:17:14 +0000 (05:17 +0000)
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 <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@samba.org>
ctdb/tests/scripts/common.sh

index c1713fa..b75fe06 100644 (file)
@@ -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 <parent> <subdir> [item-to-copy]...