#! /bin/sh

# (c) Red Hat, Inc., Written by Pavel Raiskup

workdir=`pwd`

cleanup()
{
  rm -rf "$workdir"/outputdir "$workdir"/hacked_stat*
}

cleanup

# Hacked lstat() call for testing purposes!
CPIO='LD_PRELOAD=$PWD/libhack.so cpio'

echo content > hacked_stat
ln hacked_stat hacked_stat_link

find hacked_stat* | eval "$CPIO -o -H newc" > broken.cpio

mkdir -p outputdir
cd outputdir
cpio -i < ../broken.cpio

size=`stat --printf "%s\n" hacked_stat`
if test "$size" = 0
then
    echo "FAIL"
    rc=1
else
    echo "OK"
fi

cleanup
exit $rc
