1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-04-20 02:36:16 +02:00

chown: port test to macOS 12.6 nogroup user

* tests/chown/preserve-root.sh (id_g): Set to empty if id -gn
reports that it is nogroup, and skip that part of the test.
This commit is contained in:
Paul Eggert
2024-11-19 09:53:17 -08:00
parent e3ccd26aca
commit 2a49f56906

View File

@@ -20,6 +20,11 @@
print_ver_ chown
skip_if_root_
id_g=$(id -g) && test -n "$id_g" || framework_failure_
case $(id -gn) in
nogroup) id_g= ;; # In macOS, users can be in nogroup but cannot chgrp to it.
esac
mkdir d && ln -s / d/slink-to-root
@@ -39,14 +44,15 @@ chmod -R --preserve-root u+r / >> out 2>&1 && fail=1
# Contrary to the above commands, these two should succeed.
echo '==== test -RHh' >> out || framework_failure_
chown -RHh --preserve-root $(id -u) d >> out 2>&1 || fail=1
chgrp -RHh --preserve-root $(id -g) d >> out 2>&1 || fail=1
test -z "$id_g" || chgrp -RHh --preserve-root "$id_g" d >> out 2>&1 || fail=1
# These must fail.
echo '==== test -RLh' >> out || framework_failure_
chown -RLh --preserve-root $(id -u) d >> out 2>&1 && fail=1
chgrp -RLh --preserve-root $(id -g) d >> out 2>&1 && fail=1
test -n "$id_g" && chgrp -RLh --preserve-root "$id_g" d >> out 2>&1 && fail=1
cat <<\EOF > exp || framework_failure_
(
cat <<\EOF &&
chown: it is dangerous to operate recursively on '/'
chown: use --no-preserve-root to override this failsafe
chgrp: it is dangerous to operate recursively on '/'
@@ -57,9 +63,12 @@ chmod: use --no-preserve-root to override this failsafe
==== test -RLh
chown: it is dangerous to operate recursively on 'd/slink-to-root' (same as '/')
chown: use --no-preserve-root to override this failsafe
EOF
{ test -z "$id_g" || cat <<\EOF; }
chgrp: it is dangerous to operate recursively on 'd/slink-to-root' (same as '/')
chgrp: use --no-preserve-root to override this failsafe
EOF
) > exp || framework_failure_
compare exp out || fail=1