test: avoid false failure with setgid directories
[coreutils.git] / tests / chmod / symlinks.sh
blob0bb6be0b16f88bc891611313f0d73c48ca139fe1
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 -l a/b > out || framework_failure_
52 count_755 0
53 ls -lR a/c > out || framework_failure_
54 count_755 1
56 reset_modes
57 # set a/c a/c/file and a/b/file (through symlink) to 755
58 chmod 755 -LR a/c || fail=1
59 ls -ld a/c a/c/file a/b/file > out || framework_failure_
60 count_755 3
62 reset_modes
63 # do not set /a/b/file through symlink (should try to chmod the link itself)
64 chmod 755 -RP a/c/ || fail=1
65 ls -l a/b > out || framework_failure_
66 count_755 0
68 reset_modes
69 # set /a/b/file through symlink
70 chmod 755 --dereference a/c/link || fail=1
71 ls -l a/b > out || framework_failure_
72 count_755 1
74 reset_modes
75 # do not set /a/b/file through symlink (should try to chmod the link itself)
76 chmod 755 --no-dereference a/c/link 2>err || fail=1
77 ls -l a/b > out || framework_failure_
78 count_755 0
80 # Dangling links should not induce an error if not dereferencing
81 for noderef in '-h' '-RP' '-P'; do
82 chmod 755 --no-dereference a/dangle 2>err || fail=1
83 done
84 # Dangling links should induce an error if dereferencing
85 for deref in '' '--deref' '-R'; do
86 returns_ 1 chmod 755 $deref a/dangle 2>err || fail=1
87 done
89 Exit $fail