tests: avoid triggering obsolete tail option processing
[coreutils.git] / tests / chmod / symlinks.sh
blob0317cc360bc76fb5e6d712cd6f978ad5e835b021
1 #!/bin/sh
2 # Verify chmod symlink handling options
4 # Copyright (C) 2024 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_ chmod
22 #dirs
23 mkdir -p a/b a/c || framework_failure_
24 #files
25 touch a/b/file a/c/file || framework_failure_
26 #dangling link
27 ln -s foo a/dangle || framework_failure_
28 #link to file
29 ln -s ../b/file a/c/link || framework_failure_
30 #link to dir
31 ln -s b a/dirlink || framework_failure_
33 # tree -F a
34 # a/
35 # |-- b/
36 # | '-- file
37 # |-- c/
38 # | |-- file
39 # | '-- link -> ../b/file
40 # |-- dangle -> foo
41 # '-- dirlink -> b/
43 reset_modes() { chmod =777 a/b a/c a/b/file a/c/file || fail=1; }
44 count_755() {
45 test "$(grep 'rwxr-xr-x' 'out' | wc -l)" = "$1" || { cat out; fail=1; }
48 reset_modes
49 # -R (with default -H) does not deref traversed symlinks (only cli args)
50 chmod 755 -R a/c || fail=1
51 ls -ld a/c a/c/file a/b/file > out || framework_failure_
52 count_755 2
54 reset_modes
55 # set a/c a/c/file and a/b/file (through symlink) to 755
56 chmod 755 -LR a/c || fail=1
57 ls -ld a/c a/c/file a/b/file > out || framework_failure_
58 count_755 3
60 reset_modes
61 # do not set /a/b/file through symlink (should try to chmod the link itself)
62 chmod 755 -RP a/c/ || fail=1
63 ls -l a/b > out || framework_failure_
64 count_755 0
66 reset_modes
67 # set /a/b/file through symlink
68 chmod 755 --dereference a/c/link || fail=1
69 ls -l a/b > out || framework_failure_
70 count_755 1
72 reset_modes
73 # do not set /a/b/file through symlink (should try to chmod the link itself)
74 chmod 755 --no-dereference a/c/link 2>err || fail=1
75 ls -l a/b > out || framework_failure_
76 count_755 0
78 # Dangling links should not induce an error if not dereferencing
79 for noderef in '-h' '-RP' '-P'; do
80 chmod 755 --no-dereference a/dangle 2>err || fail=1
81 done
82 # Dangling links should induce an error if dereferencing
83 for deref in '' '--deref' '-R'; do
84 returns_ 1 chmod 755 $deref a/dangle 2>err || fail=1
85 done
87 Exit $fail