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
23 mkdir
-p a
/b a
/c || framework_failure_
25 touch a
/b
/file a
/c
/file || framework_failure_
27 ln -s foo a
/dangle || framework_failure_
29 ln -s ..
/b
/file a
/c
/link || framework_failure_
31 ln -s b a
/dirlink || framework_failure_
39 # | '-- link -> ../b/file
43 reset_modes
() { chmod =777 a
/b a
/c a
/b
/file a
/c
/file || fail
=1; }
45 test "$(grep 'rwxr-xr-x' 'out' | wc -l)" = "$1" ||
{ cat out
; fail
=1; }
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_
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_
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_
67 # set /a/b/file through symlink
68 chmod 755 --dereference a
/c
/link || fail
=1
69 ls -l a
/b
> out || framework_failure_
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_
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
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