Subject: bug#60620: [PATCH] copy.c: replace set_acl() with chmod_or_fchmod()

From: Ondrej Valousek <[email-masked]>
Date: Fri, 6 Jan 2023 16:23:06 +0100

This patch replaces set_acl() funclion call with chmod_or_fchmod()
Both functions works (AFAIK) the same way (at least in Linux) so should be possible.
Using chmod_or_fchmod would also help us to reduce dependency on libacl
(see the forthcoming patch to qcopy-acl.c from Gnulib).

Ondrej

---
 src/copy.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/copy.c b/src/copy.c
index 519c43b00..1e69f3090 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -833,7 +833,7 @@ set_owner (const struct cp_options *x, char const *dst_name,
       if ((USE_ACL
            || (old_mode & CHMOD_MODE_BITS
                & (~new_mode | S_ISUID | S_ISGID | S_ISVTX)))
-          && qset_acl (dst_name, dest_desc, restrictive_temp_mode) != 0)
+          && chmod_or_fchmod (dst_name, dest_desc, restrictive_temp_mode) != 0)
         {
           if (! owner_failure_ok (x))
             error (0, errno, _("clearing permissions for %s"),
@@ -1490,12 +1490,12 @@ copy_reg (char const *src_name, char const *dst_name,
     }
   else if (x->set_mode)
     {
-      if (set_acl (dst_name, dest_desc, x->mode) != 0)
+      if (chmod_or_fchmod (dst_name, dest_desc, x->mode) != 0)
         return_val = false;
     }
   else if (x->explicit_no_preserve_mode && *new_dst)
     {
-      if (set_acl (dst_name, dest_desc, MODE_RW_UGO & ~cached_umask ()) != 0)
+      if (chmod_or_fchmod (dst_name, dest_desc, MODE_RW_UGO & ~cached_umask ()) != 0)
         return_val = false;
     }
   else if (omitted_permissions | extra_permissions)
@@ -3060,14 +3060,14 @@ copy_internal (char const *src_name, char const *dst_name,
     }
   else if (x->set_mode)
     {
-      if (set_acl (dst_name, -1, x->mode) != 0)
+      if (chmod_or_fchmod (dst_name, -1, x->mode) != 0)
         return false;
     }
   else if (x->explicit_no_preserve_mode && new_dst)
     {
       int default_permissions = S_ISDIR (src_mode) || S_ISSOCK (src_mode)
                                 ? S_IRWXUGO : MODE_RW_UGO;
-      if (set_acl (dst_name, -1, default_permissions & ~cached_umask ()) != 0)
+      if (chmod_or_fchmod (dst_name, -1, default_permissions & ~cached_umask ()) != 0)
         return false;
     }
   else
-- 
2.39.0