tests: add test for locale decimal processing
[coreutils.git] / tests / misc / readlink-fp-loop.sh
blobd5a4b2f0fa74cc951555947a3142c4a3c858648b
1 #!/bin/sh
2 # readlink from 6.9 would fail with a false-positive symlink loop error
4 # Copyright (C) 2007-2019 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ readlink pwd
21 cwd=$(env pwd -P)
23 # To trigger this bug, we have to construct a name/situation during
24 # the resolution of which the code dereferences the same symlink (S)
25 # two different times with no actual loop. In addition, arrange
26 # so that the second and fourth calls to readlink operate on S.
28 ln -s s p || framework_failure_
29 ln -s d s || framework_failure_
30 mkdir d || framework_failure_
31 echo 2 > d/2 || framework_failure_
32 ln -s ../s/2 d/1 || framework_failure_
34 # With coreutils-6.9, this would fail with ELOOP.
35 readlink -v -e p/1 > out || fail=1
36 # readlink -e d/2 > exp || fail=1
37 echo "$cwd/d/2" > exp || framework_failure_
38 compare exp out || fail=1
40 # Construct a real loop and make sure readlink still detects it.
41 ln -sf ../s/1 d/2 || framework_failure_
42 readlink -v -e p/1 2> out && fail=1
43 readlink_msg=$(cat out)
44 case $readlink_msg in
45 "readlink: p/1: "*) ;;
46 *) fail=1;;
47 esac
48 symlink_loop_msg=${readlink_msg#"readlink: p/1: "}
50 # Exercise the hash table code.
51 ln -nsf ../s/3 d/2 || framework_failure_
52 ln -nsf ../p/4 d/3 || framework_failure_
53 ln -nsf ../p/5 d/4 || framework_failure_
54 ln -nsf ../p/6 d/5 || framework_failure_
55 ln -nsf ../p/7 d/6 || framework_failure_
56 ln -nsf ../p/8 d/7 || framework_failure_
57 echo x > d/8 || framework_failure_
58 readlink -v -e p/1 > out || fail=1
59 echo "$cwd/d/8" > exp || framework_failure_
60 compare exp out || fail=1
62 # A trivial loop
63 ln -s loop loop
64 readlink -v -e loop 2> out && fail=1
65 echo "readlink: loop: $symlink_loop_msg" > exp || framework_failure_
66 compare exp out || fail=1
68 Exit $fail