Blame tests/ln/misc.sh

Packit 9e4112
#!/bin/sh
Packit 9e4112
# Miscellaneous tests for "ln".
Packit 9e4112
Packit 9e4112
# Copyright (C) 1998-2018 Free Software Foundation, Inc.
Packit 9e4112
Packit 9e4112
# This program is free software: you can redistribute it and/or modify
Packit 9e4112
# it under the terms of the GNU General Public License as published by
Packit 9e4112
# the Free Software Foundation, either version 3 of the License, or
Packit 9e4112
# (at your option) any later version.
Packit 9e4112
Packit 9e4112
# This program is distributed in the hope that it will be useful,
Packit 9e4112
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 9e4112
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 9e4112
# GNU General Public License for more details.
Packit 9e4112
Packit 9e4112
# You should have received a copy of the GNU General Public License
Packit 9e4112
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
Packit 9e4112
Packit 9e4112
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
Packit 9e4112
print_ver_ ln
Packit 9e4112
Packit 9e4112
t=tln-symlink
Packit 9e4112
d=tln-subdir
Packit 9e4112
ld=tln-symlink-to-subdir
Packit 9e4112
f=tln-file
Packit 9e4112
Packit 9e4112
# Create a simple symlink with both source and destination files
Packit 9e4112
# in current directory.
Packit 9e4112
touch $f || framework_failure_
Packit 9e4112
rm -f $t || framework_failure_
Packit 9e4112
ln -s $f $t || fail=1
Packit 9e4112
test -f $t || fail=1
Packit 9e4112
rm $t $f
Packit 9e4112
Packit 9e4112
# Create a symlink with source file and explicit destination directory/file.
Packit 9e4112
touch $f || framework_failure_
Packit 9e4112
rm -rf $d || framework_failure_
Packit 9e4112
mkdir $d || framework_failure_
Packit 9e4112
ln -s ../$f $d/$t || fail=1
Packit 9e4112
test -f $d/$t || fail=1
Packit 9e4112
rm -rf $d $f
Packit 9e4112
Packit 9e4112
# Create a symlink with source file and destination directory.
Packit 9e4112
touch $f || framework_failure_
Packit 9e4112
rm -rf $d || framework_failure_
Packit 9e4112
mkdir $d || framework_failure_
Packit 9e4112
ln -s ../$f $d || fail=1
Packit 9e4112
test -f $d/$f || fail=1
Packit 9e4112
rm -rf $d $f
Packit 9e4112
Packit 9e4112
# See whether a trailing slash is followed too far.
Packit 9e4112
touch $f || framework_failure_
Packit 9e4112
rm -rf $d || framework_failure_
Packit 9e4112
mkdir $d $d/$f || framework_failure_
Packit 9e4112
returns_ 1 ln $f $d/ 2> /dev/null || fail=1
Packit 9e4112
returns_ 1 ln -s $f $d/ 2> /dev/null || fail=1
Packit 9e4112
rm -rf $d $f
Packit 9e4112
Packit 9e4112
# Make sure we get a failure with existing dest without -f option
Packit 9e4112
touch $t || framework_failure_
Packit 9e4112
# FIXME: don't ignore the error message but rather test
Packit 9e4112
# it to make sure it's the right one.
Packit 9e4112
returns_ 1 ln -s $t $t 2> /dev/null || fail=1
Packit 9e4112
rm $t
Packit 9e4112
Packit 9e4112
# Make sure -sf fails when src and dest are the same
Packit 9e4112
touch $t || framework_failure_
Packit 9e4112
returns_ 1 ln -sf $t $t 2> /dev/null || fail=1
Packit 9e4112
rm $t
Packit 9e4112
Packit 9e4112
# Create a symlink with source file and no explicit directory
Packit 9e4112
rm -rf $d || framework_failure_
Packit 9e4112
mkdir $d || framework_failure_
Packit 9e4112
touch $d/$f || framework_failure_
Packit 9e4112
ln -s $d/$f || fail=1
Packit 9e4112
test -f $f || fail=1
Packit 9e4112
rm -rf $d $f
Packit 9e4112
Packit 9e4112
# Create a symlink with source file and destination symlink-to-directory.
Packit 9e4112
rm -rf $d $f $ld || framework_failure_
Packit 9e4112
touch $f || framework_failure_
Packit 9e4112
mkdir $d || framework_failure_
Packit 9e4112
ln -s $d $ld
Packit 9e4112
ln -s ../$f $ld || fail=1
Packit 9e4112
test -f $d/$f || fail=1
Packit 9e4112
rm -rf $d $f $ld
Packit 9e4112
Packit 9e4112
# Create a symlink with source file and destination symlink-to-directory.
Packit 9e4112
# BUT use the new --no-dereference option.
Packit 9e4112
rm -rf $d $f $ld || framework_failure_
Packit 9e4112
touch $f || framework_failure_
Packit 9e4112
mkdir $d || framework_failure_
Packit 9e4112
ln -s $d $ld
Packit 9e4112
af=$(pwd)/$f
Packit 9e4112
ln --no-dereference -fs "$af" $ld || fail=1
Packit 9e4112
test -f $ld || fail=1
Packit 9e4112
rm -rf $d $f $ld
Packit 9e4112
Packit 9e4112
# Try to create a symlink with backup where the destination file exists
Packit 9e4112
# and the backup file name is a hard link to the destination file.
Packit 9e4112
touch a b || framework_failure_
Packit 9e4112
ln b b~ || framework_failure_
Packit 9e4112
ln -f --b=simple a b || fail=1
Packit 9e4112
Packit 9e4112
# ===================================================
Packit 9e4112
Packit 9e4112
# Make sure ln can make simple backups.
Packit 9e4112
# This was fixed in 4.0.34.  Broken in 4.0r.
Packit 9e4112
for cmd in ln cp mv ginstall; do
Packit 9e4112
  rm -rf a x a.orig
Packit 9e4112
  touch a x || framework_failure_
Packit 9e4112
  $cmd --backup=simple --suffix=.orig x a || fail=1
Packit 9e4112
  test -f a.orig || fail=1
Packit 9e4112
done
Packit 9e4112
Packit 9e4112
# ===================================================
Packit 9e4112
# With coreutils-5.2.1, this would mistakenly access argv[1][-1].
Packit 9e4112
# I'm including it here, in case some day programs like valgrind detect that.
Packit 9e4112
# Purify probably would have done so.
Packit 9e4112
ln foo '' 2> /dev/null
Packit 9e4112
Packit 9e4112
# ===================================================
Packit 9e4112
Packit 9e4112
Exit $fail