Tizen 2.0 Release
[external/tizen-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 # Copyright (C) 2002, 2004, 2005, 2006 Free Software Foundation, Inc.
8
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
13
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 # 02110-1301, USA.
23
24 if test "$VERBOSE" = yes; then
25   set -x
26   rm --version
27 fi
28
29 pwd=`pwd`
30 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
31 trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0
32 trap '(exit $?); exit' 1 2 13 15
33
34 framework_failure=0
35 mkdir -p $tmp || framework_failure=1
36 cd $tmp || framework_failure=1
37 ln -s no-file dangle
38 ln -s / symlink
39
40 if test $framework_failure = 1; then
41   echo "$0: failure in testing framework" 1>&2
42   (exit 1); exit 1
43 fi
44
45 fail=0
46
47 rm ---presume-input-tty dangle symlink &
48 pid=$!
49 # The buggy rm (fileutils-4.1.9) would hang here, waiting for input.
50
51 # Give the working rm a chance to remove the file.
52 sleep 1
53
54 # The file must no longer exist.
55 ls -l dangle > /dev/null 2>&1 && fail=1
56 ls -l symlink > /dev/null 2>&1 && fail=1
57
58 kill $pid > /dev/null 2>&1
59
60 (exit $fail); exit $fail