4625aa0538c77647e61f4e443e61eb11701c8cfd
[platform/upstream/coreutils.git] / tests / du / slink
1 #!/bin/sh
2 # Ensure that the size of a long-named-symlink is > 0.
3
4 if test "$VERBOSE" = yes; then
5   set -x
6   du --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
18 # Determine if `.' is on a local (would non-NFS be sufficient?) file system.
19 # On at least some NFS implementations, symlinks never take up space,
20 df --local . | tail -n +2 > tmp
21 # So if this is a non-local file system, skip the test.
22 if test -s tmp; then
23   : # Ok.
24 else
25   echo "$0: skipping this test, since \`.' is on a non-local file system" 1>&2
26   (exit 77); exit 77
27 fi
28
29 df --type=xfs . | tail -n +2 > tmp
30 if test -s tmp; then
31   # At least on Irix-6.5.19, when using an xfs file system,
32   # each created symlink (name lengths up to 255) would have a size of `0'.
33   echo "$0: skipping this test, since \`.' is on an XFS file system" 1>&2
34   (exit 77); exit 77
35 fi
36
37 if test $framework_failure = 1; then
38   echo "$0: failure in testing framework" 1>&2
39   (exit 1); exit 1
40 fi
41
42 fail=0
43 symlink_name_lengths='1 15 16 31 32 59 60 63 64 127 128 255 256 511 512 1024'
44 for len in $symlink_name_lengths; do
45   name=`seq 1 $len|tr -c x y |head -c$len`
46   # Record the names of symlinks that are successfully created.
47   ln -fs $name $len > /dev/null 2>&1 \
48     && symlinks="$symlinks $len"
49 done
50
51 du -a $symlinks > out || fail=1
52
53 # Require that at least one of these symlinks has a non-zero size.
54 grep '^[1-9]' out > /dev/null || fail=1
55
56 (exit $fail); exit $fail