1#!/bin/sh
2# Test POSIX-mandated -H option.
3
4# Copyright (C) 2003-2023 Free Software Foundation, Inc.
5
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.
10
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.
15
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/>.
18
19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20print_ver_ chgrp
21require_membership_in_two_groups_
22require_local_dir_
23
24set _ $groups; shift
25g1=$1
26g2=$2
27
28mkdir 1 2 3 || framework_failure_
29touch 1/1F 2/2F 3/3F || framework_failure_
30ln -s 1 1s || framework_failure_
31ln -s ../3 2/2s || framework_failure_
32chgrp -R $g1 1 2 3 || framework_failure_
33
34
35chgrp --preserve-root -H -R $g2 1s 2 || fail=1
36
37# These must have group $g2.
38# =========================
39changed='
401
411/1F
422
432/2F
443
45'
46for i in $changed; do
47  # Filter out symlinks (entries that end in 's'), since it's not
48  # possible to change their group/owner information on some systems.
49  case $i in *s) continue;; esac
50  set _ $(ls -dgn $i); shift
51  group=$3
52  test $group = $g2 || fail=1
53done
54
55# These must have group $g1.
56# =========================
57not_changed='
581s
592/2s
603/3F
61'
62for i in $not_changed; do
63  # Filter out symlinks (entries that end in 's'), since it's not
64  # possible to change their group/owner information on some systems.
65  case $i in *s) continue;; esac
66  set _ $(ls -dgn $i); shift
67  group=$3
68  test $group = $g1 || fail=1
69done
70
71Exit $fail
72