diff options
| author | Emmanuel Dreyfus <manu@netbsd.org> | 2014-12-04 06:53:25 +0100 | 
|---|---|---|
| committer | Vijay Bellur <vbellur@redhat.com> | 2014-12-04 02:57:42 -0800 | 
| commit | ae744a27602488239ef681510412d0c64607a87f (patch) | |
| tree | dca55fcd3c66c66ff562c88b960855224f2bfcb8 | |
| parent | 811abf66d158efa037f1314792f7c674a7640c50 (diff) | |
Regression test portability: stat
Improve Linux stat emulation for BSD so that it can handle multiple
files at once. This is required now tests/basic/afr/data-self-heal.t
uses that syntax.
BUG: 1129939
Change-Id: I2720d0e8a0d4dedbb8d51fcde3586b4e7d8bb492
Signed-off-by: Emmanuel Dreyfus <manu@netbsd.org>
Reviewed-on: http://review.gluster.org/9232
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Vijay Bellur <vbellur@redhat.com>
| -rw-r--r-- | tests/include.rc | 103 | 
1 files changed, 51 insertions, 52 deletions
diff --git a/tests/include.rc b/tests/include.rc index ab26755c639..75db2d10d0e 100644 --- a/tests/include.rc +++ b/tests/include.rc @@ -311,63 +311,62 @@ stat -c %s /dev/null > /dev/null 2>&1 || {      local f=""      if [ "x$1" = "x-c" ] ; then -      argc=3 -      format=$2 -      f=$3 +      oformat=$2 +      shift +      shift +      files=$@      else -      argc=1 -      f=$1 +      files=$@      fi -    if [ $# -ne $argc ] ; then -      echo 'Usage: stat [-c format] file' -      exit 2; -    fi +    for f in $files ; do +        format=$oformat -    # %t/%T should return 0 for non devices. -    case "${format}" in -    *%t*|*%T*) -      `which stat` -f '%HT' $f | grep -q 'Device$' || \ -         format=`echo "${format}" | sed 's/%t/0/g; s/%T/0/g;'` -      ;; -    *) -      ;; -    esac +      # %t/%T should return 0 for non devices. +      case "${format}" in +      *%t*|*%T*) +        `which stat` -f '%HT' $f | grep -q 'Device$' || \ +           format=`echo "${format}" | sed 's/%t/0/g; s/%T/0/g;'` +        ;; +      *) +        ;; +      esac -    if [ "x${format}" = "x" ] ; then -      `which stat` $f -    else -       cmd="" -       case $format in  -       *%u*) cmd="${cmd} s/%u/`$( which stat ) -f %u $f`/g;" ;&  -       *%g*) cmd="${cmd} s/%g/`$( which stat ) -f %g $f`/g;" ;& -       *%a*) cmd="${cmd} s/%a/`$( which stat ) -f %p $f | -                  sed 's/^..//; s/^0//'`/g;" ;& -       *%A*) cmd="${cmd} s/%A/`ls -ld $f|awk '{print $1}'`/g;" ;& -       *%s*) cmd="${cmd} s/%s/`$( which stat ) -f %z $f`/g;" ;& -       *%h*) cmd="${cmd} s/%h/`$( which stat ) -f %l $f`/g;" ;& -       *%F*) cmd="${cmd} s/%F/`$( which stat ) -f %HT $f | sed ' -          s/Directory/directory/; -          s/Fifo File/fifo/; -          s/Symbolic Link/symbolic link/; -          s/Regular File/regular file/; -          s/Block Device/block special file/; -          s/Character Device/character special file/; -         ' | sed \"$( -           test -s $f || echo 's/regular file/regular empty file/g' -          )\"`/g;" ;& -       *%n*) cmd="${cmd} s|%n|`$( which stat ) -f %N $f`|g;" ;& -       *%Y*) cmd="${cmd} s/%Y/`$( which stat ) -f %m $f`/g;" ;& -       *%X*) cmd="${cmd} s/%X/`$( which stat ) -f %a $f`/g;" ;& -       *%Z*) cmd="${cmd} s/%Z/`$( which stat ) -f %c $f`/g;" ;& -       *%b*) cmd="${cmd} s/%b/`$( which stat ) -f %b $f`/g;" ;& -       *%B*) cmd="${cmd} s/%B/512/g;" ;& -       *%t*) cmd="${cmd} s/%t/`$( which stat ) -f %XHr $f`/g;" ;& -       *%T*) cmd="${cmd} s/%T/`$( which stat ) -f %XLr $f`/g;" ;& -       esac - -       `which stat` -f "`echo $format|sed \"$cmd\"`" $f -    fi +      if [ "x${format}" = "x" ] ; then +        `which stat` $f +      else +         cmd="" +         case $format in +         *%u*) cmd="${cmd} s/%u/`$( which stat ) -f %u $f`/g;" ;& +         *%g*) cmd="${cmd} s/%g/`$( which stat ) -f %g $f`/g;" ;& +         *%a*) cmd="${cmd} s/%a/`$( which stat ) -f %p $f | +                    sed 's/^..//; s/^0//'`/g;" ;& +         *%A*) cmd="${cmd} s/%A/`ls -ld $f|awk '{print $1}'`/g;" ;& +         *%s*) cmd="${cmd} s/%s/`$( which stat ) -f %z $f`/g;" ;& +         *%h*) cmd="${cmd} s/%h/`$( which stat ) -f %l $f`/g;" ;& +         *%F*) cmd="${cmd} s/%F/`$( which stat ) -f %HT $f | sed ' +            s/Directory/directory/; +            s/Fifo File/fifo/; +            s/Symbolic Link/symbolic link/; +            s/Regular File/regular file/; +            s/Block Device/block special file/; +            s/Character Device/character special file/; +           ' | sed \"$( +             test -s $f || echo 's/regular file/regular empty file/g' +            )\"`/g;" ;& +         *%n*) cmd="${cmd} s|%n|`$( which stat ) -f %N $f`|g;" ;& +         *%Y*) cmd="${cmd} s/%Y/`$( which stat ) -f %m $f`/g;" ;& +         *%X*) cmd="${cmd} s/%X/`$( which stat ) -f %a $f`/g;" ;& +         *%Z*) cmd="${cmd} s/%Z/`$( which stat ) -f %c $f`/g;" ;& +         *%b*) cmd="${cmd} s/%b/`$( which stat ) -f %b $f`/g;" ;& +         *%B*) cmd="${cmd} s/%B/512/g;" ;& +         *%t*) cmd="${cmd} s/%t/`$( which stat ) -f %XHr $f`/g;" ;& +         *%T*) cmd="${cmd} s/%T/`$( which stat ) -f %XLr $f`/g;" ;& +         esac + +         `which stat` -f "`echo $format|sed \"$cmd\"`" $f +      fi +    done    }  }  | 
