Change do_chmod to always try lchmod() first (when possible).
authorWayne Davison <wayne@opencoder.net>
Fri, 1 Oct 2021 20:28:57 +0000 (13:28 -0700)
committerWayne Davison <wayne@opencoder.net>
Fri, 1 Oct 2021 20:28:57 +0000 (13:28 -0700)
syscall.c

index 181be11dba495b8678c001cfd64f8c5d35cb9393..bf0de8ba41051168c8e4fcd5a7aa138f5efd655e 100644 (file)
--- a/syscall.c
+++ b/syscall.c
@@ -231,19 +231,13 @@ int do_open(const char *pathname, int flags, mode_t mode)
 #ifdef HAVE_CHMOD
 int do_chmod(const char *path, mode_t mode)
 {
-       static int switch_step = 0;
        int code;
        if (dry_run) return 0;
        RETURN_ERROR_IF_RO_OR_LO;
-       switch (switch_step) {
 #ifdef HAVE_LCHMOD
-#include "case_N.h"
-               if ((code = lchmod(path, mode & CHMOD_BITS)) == 0 || errno != ENOTSUP)
-                       break;
-               switch_step++;
+       if ((code = lchmod(path, mode & CHMOD_BITS)) < 0 && errno == ENOTSUP)
 #endif
-
-#include "case_N.h"
+       {
                if (S_ISLNK(mode)) {
 # if defined HAVE_SETATTRLIST
                        struct attrlist attrList;
@@ -258,7 +252,6 @@ int do_chmod(const char *path, mode_t mode)
 # endif
                } else
                        code = chmod(path, mode & CHMOD_BITS); /* DISCOURAGED FUNCTION */
-               break;
        }
        if (code != 0 && (preserve_perms || preserve_executability))
                return code;