1072776cb5b0ff53495741aecc7ffe9020fa8d10
[platform/upstream/coreutils.git] / tests / rm / dangling-symlink
1 #!/bin/sh
2 # rm should not prompt before removing a dangling symlink.
3 # Likewise for a non-dangling symlink.
4 # But for fileutils-4.1.9, it would do the former and
5 # for fileutils-4.1.10 the latter.
6
7 if test "$VERBOSE" = yes; then
8   set -x
9   rm --version
10 fi
11
12 pwd=`pwd`
13 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
14 trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0
15 trap '(exit $?); exit' 1 2 13 15
16
17 framework_failure=0
18 mkdir -p $tmp || framework_failure=1
19 cd $tmp || framework_failure=1
20 ln -s no-file dangle
21 ln -s / symlink
22
23 if test $framework_failure = 1; then
24   echo "$0: failure in testing framework" 1>&2
25   (exit 1); exit 1
26 fi
27
28 fail=0
29
30 rm ---presume-input-tty dangle symlink &
31 pid=$!
32 # The buggy rm (fileutils-4.1.9) would hang here, waiting for input.
33
34 # Give the working rm a chance to remove the file.
35 sleep 1
36
37 # The file must no longer exist.
38 ls -l dangle > /dev/null 2>&1 && fail=1
39 ls -l symlink > /dev/null 2>&1 && fail=1
40
41 kill $pid > /dev/null 2>&1
42
43 (exit $fail); exit $fail