]> Savannah Git Hosting - gnulib.git/commitdiff
file-has-acl: always return false when ACLs aren't supported
authorPádraig Brady <P@draigBrady.com>
Sat, 25 Apr 2015 20:49:43 +0000 (21:49 +0100)
committerPádraig Brady <P@draigBrady.com>
Sun, 26 Apr 2015 10:39:47 +0000 (11:39 +0100)
* lib/file-has-acl.c (file_has_acl): Consistent with other paths,
change the GNU/Linux getxattr path, to transform "not supported"
errors to a false return rather than an error.  This is handled
within file_has_acl() due to the platform specific tests to
determine if ACLs are not supported.

ChangeLog
lib/file-has-acl.c

index ec5cd549ba136eafc367bf4ca8e43ca492233e79..eb1110be8aa71d6701b2125fb1f5a82b2622a3f1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2015-04-26  Pádraig Brady  <P@draigBrady.com>
+
+       file-has-acl: always return false when ACLs aren't supported
+       * lib/file-has-acl.c (file_has_acl): Consistent with other paths,
+       change the GNU/Linux getxattr path, to transform "not supported"
+       errors to a false return rather than an error.  This is handled
+       within file_has_acl() due to the platform specific tests to
+       determine if ACLs are not supported.
+
 2015-04-25  Paul Eggert  <eggert@cs.ucla.edu>
 
        gettext: propagate po/Makefile.in.in too
index 5dfe9a8510041ddf54b1e319b6cda2a77ec56526..d2b6a146fa224152c396293d7ee8dc0f58429570 100644 (file)
 # include <linux/xattr.h>
 #endif
 
-/* Return 1 if NAME has a nontrivial access control list, 0 if NAME
-   only has no or a base access control list, and -1 (setting errno)
-   on error.  SB must be set to the stat buffer of NAME, obtained
-   through stat() or lstat().  */
+/* Return 1 if NAME has a nontrivial access control list,
+   0 if ACLs are not supported, or if NAME has no or only a base ACL,
+   and -1 (setting errno) on error.  Note callers can determine
+   if ACLs are not supported as errno is set in that case also.
+   SB must be set to the stat buffer of NAME,
+   obtained through stat() or lstat().  */
 
 int
 file_has_acl (char const *name, struct stat const *sb)
@@ -54,25 +56,23 @@ file_has_acl (char const *name, struct stat const *sb)
       ssize_t ret;
 
       ret = getxattr (name, XATTR_NAME_POSIX_ACL_ACCESS, NULL, 0);
-      if (ret < 0)
-       {
-         if (errno != ENODATA)
-           return -1;
-       }
+      if (ret < 0 && errno == ENODATA)
+        ret = 0;
       else if (ret > 0)
-       return 1;
-      if (S_ISDIR (sb->st_mode))
-       {
-         ret = getxattr (name, XATTR_NAME_POSIX_ACL_DEFAULT, NULL, 0);
-         if (ret < 0)
-           {
-             if (errno != ENODATA)
-               return -1;
-           }
-         else if (ret > 0)
-           return 1;
-       }
-      return 0;
+        return 1;
+
+      if (ret == 0 && S_ISDIR (sb->st_mode))
+        {
+          ret = getxattr (name, XATTR_NAME_POSIX_ACL_DEFAULT, NULL, 0);
+          if (ret < 0 && errno == ENODATA)
+            ret = 0;
+          else if (ret > 0)
+            return 1;
+        }
+
+      if (ret < 0)
+        return - acl_errno_valid (errno);
+      return ret;
 
 # elif HAVE_ACL_GET_FILE