efaa02e1dc1dd61211544750b2f30eff976ad0db
[platform/upstream/coreutils.git] / tests / ls / inode
1 #!/bin/sh
2 # Make sure that ls -i works properly on symlinks.
3
4 if test "$VERBOSE" = yes; then
5   set -x
6   ls --version
7 fi
8
9 pwd=`pwd`
10 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
11 trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0
12 trap '(exit $?); exit $?' 1 2 13 15
13
14 framework_failure=0
15 mkdir -p $tmp || framework_failure=1
16 cd $tmp || framework_failure=1
17 touch f || framework_failure=1
18 ln -s f slink || framework_failure=1
19
20 if test $framework_failure = 1; then
21   echo "$0: failure in testing framework" 1>&2
22   (exit 1); exit 1
23 fi
24
25 fail=0
26
27 # When listed explicitly:
28
29 set x `ls -Ci f slink`; shift
30 test $# = 4 || fail=1
31 # The inode numbers should differ.
32 test "$1" != "$3" || fail=1
33
34 set x `ls -CLi f slink`; shift
35 test $# = 4 || fail=1
36 # With -L, they must be the same.
37 test "$1" = "$3" || fail=1
38
39 set x `ls -CHi f slink`; shift
40 test $# = 4 || fail=1
41 # With -H, they must be the same, too, from the command line.
42 # Note that POSIX says -H must make ls dereference only
43 # symlinks (specified on the command line) to directories,
44 # but the historical BSD meaning of -H is to dereference
45 # any symlink given on the command line.  For compatibility GNU ls
46 # implements the BSD semantics.
47 test "$1" = "$3" || fail=1
48
49 # When listed from a directory:
50
51 set x `ls -Ci`; shift
52 test $# = 4 || fail=1
53 # The inode numbers should differ.
54 test "$1" != "$3" || fail=1
55
56 set x `ls -CLi`; shift
57 test $# = 4 || fail=1
58 # With -L, they must be the same.
59 test "$1" = "$3" || fail=1
60
61 set x `ls -CHi`; shift
62 test $# = 4 || fail=1
63 # With -H, they must be different from inside a directory.
64 test "$1" != "$3" || fail=1
65
66 (exit $fail); exit $fail