]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: port chmod/setgid.sh to macOS 12
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 18 Feb 2023 21:29:41 +0000 (13:29 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 18 Feb 2023 21:30:10 +0000 (13:30 -0800)
* tests/chmod/setgid.sh: Try all the groups you’re a member of,
in case id -g returns 4294967295 (nogroup) which is special
and does not let you chgrp a file to it.

tests/chmod/setgid.sh

index 9f277f0becb04de44e6618689f2e4ea8936a4ae7..d7a4b3e7e38d2fcfa93ea6d0a7441902132e6455 100755 (executable)
@@ -24,6 +24,7 @@ print_ver_ chmod
 umask 0
 mkdir -m 755 d || framework_failure_
 
+# "chmod g+s d" does nothing on some NFS file systems.
 chmod g+s d 2> /dev/null && env -- test -g d ||
   {
     # This is required because on some systems (at least NetBSD 1.4.2A),
@@ -31,14 +32,12 @@ chmod g+s d 2> /dev/null && env -- test -g d ||
     # to which you belong.  When that happens, the above chmod fails.  So
     # here, upon failure, we try to set the group, then rerun the chmod command.
 
-    id_g=$(id -g) &&
-    test -n "$id_g" &&
-    chgrp "$id_g" d &&
-    chmod g+s d || framework_failure_
-  }
-
-# "chmod g+s d" does nothing on some NFS file systems.
-env -- test -g d ||
+    for id_g in $(id -g) $(id -G) ''; do
+      test -n "$id_g" || break
+      chgrp "$id_g" d && chmod g+s d && env -- test -g d && break
+    done
+    test -n "$id_g"
+  } ||
   skip_ 'cannot create setgid directories'
 
 for mode in \