Regression test portability: stat

Improve BSD compatibility for stat. The new version attemps to spawn
less stat subprocesses.

Also add translation for %X %Y and %Z

BUG: 1129939
Change-Id: I2b2134f9e8336a952aee6c7679ba0491abd5a35c
Signed-off-by: Emmanuel Dreyfus <manu@netbsd.org>
Reviewed-on: http://review.gluster.org/8565
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Harshavardhana <harsha@harshavardhana.net>
Tested-by: Harshavardhana <harsha@harshavardhana.net>
This commit is contained in:
Emmanuel Dreyfus 2014-08-29 15:23:21 +02:00 committed by Harshavardhana
parent 192d5e6654
commit f54dd171bc

View File

@ -323,28 +323,36 @@ stat -c %s /dev/null > /dev/null 2>&1 || {
if [ "x${format}" = "x" ] ; then
`which stat` $f
else
echo ${format} | sed "
s/%u/`$( which stat ) -f %u $f`/g;
s/%g/`$( which stat ) -f %g $f`/g;
s/%a/`$( which stat ) -f %p $f |sed 's/^..//; s/^0//'`/g;
s/%A/`ls -l $f|awk '{print $1}'`/g;
s/%s/`$( which stat ) -f %z $f`/g;
s/%h/`$( which stat ) -f %l $f`/g;
s/%F/`$( which stat ) -f %HT $f | sed '
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/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;
s|%n|`$( which stat ) -f %N $f`|g;
s/%Y/`$( which stat ) -f %m $f`/g;
s/%b/`$( which stat ) -f %b $f`/g;
s/%B/512/g;
"
' | 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
}
}