From 2a49f569060ed1d2c72739daeaf9356bca0c5109 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 19 Nov 2024 09:53:17 -0800 Subject: [PATCH] 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. --- tests/chown/preserve-root.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/chown/preserve-root.sh b/tests/chown/preserve-root.sh index 3375a496c..9f28679fc 100755 --- a/tests/chown/preserve-root.sh +++ b/tests/chown/preserve-root.sh @@ -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 -- 2.11.4.GIT