When an NFS4 ACL was successfully copied, skip resetting POSIX ACLs.

* lib/qcopy-acl.c (struct copy_context): Add an nfs4_acl field.
(is_attr_permissions): Set the new field when seeing an NFS4 ACL.
(qcopy_acl): Move the inherited permission removal code further down.
Guard it by the USE_ACL macro.  When an NFS4 ACL was successfully set,
skip removing inherited POSIX ACLs.  When removing inherited permissions
fails with errno == EOPNOTSUPP, there are no permissions to remove and
we are done.
---
 lib/qcopy-acl.c | 56 +++++++++++++++++++++++++++++++++----------------
 1 file changed, 38 insertions(+), 18 deletions(-)

diff --git a/lib/qcopy-acl.c b/lib/qcopy-acl.c
index d149b65c52..075a0509d5 100644
--- a/lib/qcopy-acl.c
+++ b/lib/qcopy-acl.c
@@ -55,6 +55,7 @@ struct copy_context
     struct error_context ctx;
     bool posix_acl_access;
     bool posix_acl_default;
+    bool nfs4_acl;
   };
 
 /* Returns 1 if NAME is the name of an extended attribute that is related
@@ -79,8 +80,12 @@ is_attr_permissions (const char *name, struct error_context 
*ctx)
       copy_ctx->posix_acl_default = true;
       return true;
     }
-  return streq (name, XATTR_NAME_NFSV4_ACL)
-         || attr_copy_action (name, ctx) == ATTR_ACTION_PERMISSIONS;
+  if (streq (name, XATTR_NAME_NFSV4_ACL))
+    {
+      copy_ctx->nfs4_acl = true;
+      return true;
+    }
+  return attr_copy_action (name, ctx) == ATTR_ACTION_PERMISSIONS;
 }
 
 #endif  /* USE_XATTR */
@@ -124,22 +129,6 @@ qcopy_acl (const char *src_name, int source_desc, const 
char *dst_name,
         : attr_copy_fd (src_name, source_desc, dst_name, dest_desc,
                         is_attr_permissions, &copied.ctx);
 
-      if (ret == 0 && !copied.posix_acl_access)
-        {
-         acl_t acl = acl_from_mode (mode);
-         ret = dest_desc < 0
-           ? acl_set_file (dst_name, ACL_TYPE_ACCESS, acl)
-           : acl_set_fd (dest_desc, acl);
-         acl_free (acl);
-       }
-
-      if (ret == 0 && S_ISDIR (mode) && !copied.posix_acl_default)
-       {
-         ret = dest_desc < 0 || ! HAVE_ACL_DELETE_DEF_FILE_AT
-          ? acl_delete_def_file (dst_name)
-          : acl_delete_def_file_at (dest_desc, "", AT_EMPTY_PATH);
-       }
-
       /* Copying can fail with EOPNOTSUPP even when the source
          permissions are trivial (Bug#78328).  Don't report an error
          in this case, as the chmod_or_fchmod suffices.  */
@@ -156,6 +145,37 @@ qcopy_acl (const char *src_name, int source_desc, const 
char *dst_name,
           aclinfo_free (&ai);
           errno = EOPNOTSUPP;
         }
+
+# if USE_ACL
+      if (! copied.nfs4_acl)
+        {
+          if (ret == 0
+              && ! copied.posix_acl_access)
+            {
+              acl_t acl = acl_from_mode (mode);
+              ret = dest_desc < 0
+                ? acl_set_file (dst_name, ACL_TYPE_ACCESS, acl)
+                : acl_set_fd (dest_desc, acl);
+              if (ret < 0 && errno == EOPNOTSUPP)
+                {
+                  ret = 0;
+                  copied.posix_acl_default = true;  /* skip */
+                }
+              acl_free (acl);
+            }
+
+          if (ret == 0
+              && S_ISDIR (mode)
+              && ! copied.posix_acl_default)
+            {
+              ret = dest_desc < 0 || ! HAVE_ACL_DELETE_DEF_FILE_AT
+               ? acl_delete_def_file (dst_name)
+               : acl_delete_def_file_at (dest_desc, "", AT_EMPTY_PATH);
+              if (ret < 0 && errno == EOPNOTSUPP)
+                ret = 0;
+            }
+        }
+# endif
     }
 #else
   /* no XATTR, so we proceed the old dusty way */

base-commit: b0805862fe1439721bfb3e1f4180571161ed6d4d
-- 
2.56.1


Reply via email to