f6a50fda8fb83856d89497e16905fea27ea34f21
[platform/upstream/coreutils.git] / tests / ls / stat-dtype
1 #!/bin/sh
2 # Ensure that ls --file-type does not call stat unnecessarily.
3 # The trick is to create an un-stat'able symlink and to see if ls
4 # can report its type nonetheless, using dirent.d_type.
5
6 if test "$VERBOSE" = yes; then
7   set -x
8   ls --version
9 fi
10
11 . $srcdir/../envvar-check
12
13 # Skip this test unless "." is on a file system with useful d_type info.
14 # FIXME: use a more dynamic test for this, since whether d_type is useful
15 # depends on much more than the file system type.  For example, with
16 # linux-2.6.15, at least tmpfs and ext3 work, but reiserfs and xfs don't.
17 # Also, tmpfs on Solaris 10 lacks d_type support.
18 skip=yes
19 fs_type=`stat -f --printf %T .`
20 test `uname -s` = Linux && test $fs_type = tmpfs && skip=no
21 test $fs_type = ext2/ext3 && skip=no
22 test $skip = yes &&
23   {
24     echo "$0: '.' is not on a suitable file system for this test" 1>&2
25     echo "$0: skipping this test" 1>&2
26     (exit 77); exit 77
27   }
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
38 mkdir d || framework_failure=1
39 ln -s / d/s || framework_failure=1
40 chmod 600 d || framework_failure=1
41
42 if test $framework_failure = 1; then
43   echo "$0: failure in testing framework" 1>&2
44   (exit 1); exit 1
45 fi
46
47 fail=0
48
49 ls --file-type d > out || fail=1
50 cat <<\EOF > exp || fail=1
51 s@
52 EOF
53
54 cmp out exp || fail=1
55 test $fail = 1 && diff out exp 2> /dev/null
56
57 (exit $fail); exit $fail