|
|
#!/bin/sh |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src |
|
|
print_ver_ cp |
|
|
|
|
|
if { grep '^#define HAVE_LINKAT 1' "$CONFIG_HEADER" > /dev/null \ |
|
|
&& grep '#undef LINKAT_SYMLINK_NOTSUP' "$CONFIG_HEADER" > /dev/null; } \ |
|
|
|| grep '^#define LINK_FOLLOWS_SYMLINKS 0' "$CONFIG_HEADER" > /dev/null; then |
|
|
|
|
|
|
|
|
ln -s testtarget test_sl || framework_failure_ |
|
|
ln -P test_sl test_hl_sl || framework_failure_ |
|
|
ino_sl="$(stat -c '%i' test_sl)" || framework_failure_ |
|
|
ino_hl="$(stat -c '%i' test_hl_sl)" || framework_failure_ |
|
|
test "$ino_sl" = "$ino_hl" && can_hardlink_to_symlink=1 |
|
|
fi |
|
|
|
|
|
mkdir dir || framework_failure_ |
|
|
> file || framework_failure_ |
|
|
ln -s dir dirlink || framework_failure_ |
|
|
ln -s file filelink || framework_failure_ |
|
|
ln -s nowhere danglink || framework_failure_ |
|
|
|
|
|
|
|
|
outformat='%s|result=%s|inode=%s|type=%s|error=%s\n' |
|
|
|
|
|
for src in dirlink filelink danglink; do |
|
|
|
|
|
tgt=$(readlink $src) || framework_failure_ |
|
|
|
|
|
|
|
|
ino_src="$(stat -c '%i' $src)" || framework_failure_ |
|
|
typ_src="$(stat -c '%F' $src)" || framework_failure_ |
|
|
ino_tgt="$(stat -c '%i' $tgt 2>/dev/null)" || ino_tgt= |
|
|
typ_tgt="$(stat -c '%F' $tgt 2>/dev/null)" || typ_tgt= |
|
|
|
|
|
for o in '' -L -H -P; do |
|
|
|
|
|
|
|
|
! test "$can_hardlink_to_symlink" && test "$o" = '-P' && continue |
|
|
|
|
|
for r in '' -R; do |
|
|
|
|
|
command="cp --link $o $r $src dst" |
|
|
$command 2> err |
|
|
result=$? |
|
|
|
|
|
|
|
|
ino_dst="$(stat -c '%i' dst 2>/dev/null)" || ini_dst= |
|
|
typ_dst="$(stat -c '%F' dst 2>/dev/null)" || typ_dst= |
|
|
|
|
|
|
|
|
printf "$outformat" \ |
|
|
"$command" \ |
|
|
"$result" \ |
|
|
"$ino_dst" \ |
|
|
"$typ_dst" \ |
|
|
"$(cat err)" \ |
|
|
> out |
|
|
|
|
|
|
|
|
if [ "$o" = "-P" ]; then |
|
|
|
|
|
exp_result=0 |
|
|
exp_inode=$ino_src |
|
|
exp_ftype=$typ_src |
|
|
exp_error= |
|
|
elif [ "$src" = 'danglink' ]; then |
|
|
|
|
|
exp_result=1 |
|
|
exp_inode= |
|
|
exp_ftype= |
|
|
exp_error="cp: cannot stat 'danglink': No such file or directory" |
|
|
elif [ "$src" = 'dirlink' ] && [ "$r" != '-R' ]; then |
|
|
|
|
|
exp_result=1 |
|
|
exp_inode= |
|
|
exp_ftype= |
|
|
exp_error="cp: -r not specified; omitting directory 'dirlink'" |
|
|
elif [ "$src" = 'dirlink' ]; then |
|
|
|
|
|
exp_result=0 |
|
|
exp_inode=$ino_dst |
|
|
exp_ftype=$typ_dst |
|
|
exp_error= |
|
|
else |
|
|
|
|
|
exp_result=0 |
|
|
exp_inode=$ino_tgt |
|
|
exp_ftype=$typ_tgt |
|
|
exp_error= |
|
|
fi |
|
|
|
|
|
|
|
|
printf "$outformat" \ |
|
|
"$command" \ |
|
|
"$exp_result" \ |
|
|
"$exp_inode" \ |
|
|
"$exp_ftype" \ |
|
|
"$exp_error" \ |
|
|
> exp |
|
|
|
|
|
compare exp out || { ls -lid $src $tgt dst; fail=1; } |
|
|
|
|
|
rm -rf dst err exp out || framework_failure_ |
|
|
done |
|
|
done |
|
|
done |
|
|
|
|
|
Exit $fail |
|
|
|