>From 3f98f3cd22850d05fe7e64212320c188c91618bf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?=
Date: Sat, 25 Apr 2015 21:49:43 +0100
Subject: [PATCH] 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.
---
lib/file-has-acl.c | 44 ++++++++++++++++++++++----------------------
1 file changed, 22 insertions(+), 22 deletions(-)
diff --git a/lib/file-has-acl.c b/lib/file-has-acl.c
index 5dfe9a8..d2b6a14 100644
--- a/lib/file-has-acl.c
+++ b/lib/file-has-acl.c
@@ -37,10 +37,12 @@
# include
#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
--
2.3.4