#!/bin/sh
set -e
echo cp-atest:
TMP="$tmp"
export PATH
umask 022

if test ! -d $TMP; then
  mkdir $TMP
fi

cd $TMP;

touch empty
chmod 0644 empty
chown 1:2 empty
cp -a empty empty-a
cp -r empty empty-r
empty_mode=`stat -c %a empty`
empty_owner=`stat -c %u:%g empty`
empty_a_mode=`stat -c %a empty-a`
empty_a_owner=`stat -c %u:%g empty-a`
empty_r_mode=`stat -c %a empty-r`
empty_r_owner=`stat -c %u:%g empty-r`

if ! [ "${empty_mode} ${empty_owner}" = "644 1:2" ]
then
	echo "'chmod' failed '${empty_mode} ${empty_owner}'">&2
	exit 1
fi

if ! [ "${empty_mode} ${empty_owner}" = "${empty_a_mode} ${empty_a_owner}" ]
then
	echo "'cp -a' sanity check failed">&2
	exit 2
fi

if ! [ "${empty_mode} 0:0" = "${empty_r_mode} ${empty_r_owner}" ]
then
	echo "'cp -r' sanity check failed: $empty_r_mode">&2
	exit 3
fi
ls -l empty*
rm -f empty*
