tests: avoid false failure due to remove() ignoring u-w on NFS
[coreutils.git] / tests / ln / hard-to-sym.sh
blob30d83c0914696c53ba373380a92f36e8195cd201
1 #!/bin/sh
2 # Tests for ln -L/-P.
4 # Copyright (C) 2009-2016 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 <http://www.gnu.org/licenses/>.
19 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ ln
23 # ===================================================
24 # ensure -s silently overrides -L, -P
25 touch a || framework_failure_
26 ln -L -s a symlink1 || fail=1
27 ln -P -s symlink1 symlink2 || fail=1
28 ln -s -L -P symlink2 symlink3 || fail=1
30 # ===================================================
31 # ensure that -L follows symlinks, and overrides -P
32 if ln -P -L symlink3 hard-to-a; then
33 ls=$(ls -lG hard-to-a)x
34 case "$ls" in
35 *'hard-to-ax') ;;
36 *'hard-to-a -> '*x) fail=1 ;;
37 *) framework_failure_ ;;
38 esac
39 else
40 fail=1
43 # ===================================================
44 # ensure that -P links (or at least duplicates) symlinks, and overrides -L
45 if ln -L -P symlink3 hard-to-3; then
46 ls=$(ls -lG hard-to-3)x
47 case "$ls" in
48 *'hard-to-3 -> symlink2x') ;;
49 *'hard-to-3x') fail=1 ;;
50 *'hard-to-3 -> '*x) fail=1 ;;
51 *) framework_failure_ ;;
52 esac
53 else
54 fail=1
57 # ===================================================
58 # Create a hard link to a dangling symlink.
59 ln -s /no-such-dir || framework_failure_
60 ln -L no-such-dir hard-to-dangle 2>err && fail=1
61 case $(cat err) in
62 *" failed to access 'no-such-dir'":*) ;;
63 *) fail=1 ;;
64 esac
65 ln -P no-such-dir hard-to-dangle || fail=1
67 # ===================================================
68 # Create a hard link to a symlink to a directory.
69 mkdir d || framework_failure_
70 ln -s d link-to-dir || framework_failure_
71 ln -L link-to-dir hard-to-dir-link 2>err && fail=1
72 case $(cat err) in
73 *": link-to-dir: hard link not allowed for directory"*) ;;
74 *) fail=1 ;;
75 esac
76 ln -P link-to-dir/ hard-to-dir-link 2>err && fail=1
77 case $(cat err) in
78 *": link-to-dir/: hard link not allowed for directory"*) ;;
79 *) fail=1 ;;
80 esac
81 ln -P link-to-dir hard-to-dir-link || fail=1
83 Exit $fail