#!/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
cp -a empty empty-a
cp -r empty empty-r
empty_mode=`stat -c %a empty`
empty_a_mode=`stat -c %a empty-a`
empty_r_mode=`stat -c %a empty-r`

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

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

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