summaryrefslogtreecommitdiffstats
path: root/fsade.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2019-05-24 23:26:43 -0400
committerTavian Barnes <tavianator@tavianator.com>2019-05-24 23:26:43 -0400
commitc6769208d4c7c774982fbb76afad0d95a6e4c9e8 (patch)
tree07e3eb40402705a480c0522ab35ec5d5aa73ade1 /fsade.c
parent3edc432a60a5db633351a52f1adbcdd0ee1ff838 (diff)
downloadbfs-c6769208d4c7c774982fbb76afad0d95a6e4c9e8.tar.xz
fsade: Fix ACL detection on macOS
Diffstat (limited to 'fsade.c')
-rw-r--r--fsade.c39
1 files changed, 29 insertions, 10 deletions
diff --git a/fsade.c b/fsade.c
index 822fbd1..8f8f8b1 100644
--- a/fsade.c
+++ b/fsade.c
@@ -104,6 +104,13 @@ static bool is_absence_error(int error) {
}
#endif
+#if __APPLE__
+ // On macOS, ENOENT can also signal that a file has no ACLs
+ if (error == ENOENT) {
+ return true;
+ }
+#endif
+
return false;
}
@@ -125,7 +132,13 @@ static int bfs_check_acl_type(const char *path, acl_type_t type) {
int ret = 0;
acl_entry_t entry;
for (int status = acl_get_entry(acl, ACL_FIRST_ENTRY, &entry);
+#if __APPLE__
+ // POSIX.1e specifies a return value of 1 for success, but macOS
+ // returns 0 instead
+ status == 0;
+#else
status > 0;
+#endif
status = acl_get_entry(acl, ACL_NEXT_ENTRY, &entry)) {
#if defined(ACL_USER_OBJ) && defined(ACL_GROUP_OBJ) && defined(ACL_OTHER)
acl_tag_t tag;
@@ -153,22 +166,28 @@ int bfs_check_acl(const struct BFTW *ftwbuf) {
const char *path = fake_at(ftwbuf);
- int error = 0;
- int ret = bfs_check_acl_type(path, ACL_TYPE_ACCESS);
- if (ret < 0) {
- error = errno;
- }
+ int error = ENOTSUP;
+ int ret = -1;
- if (ret <= 0 && ftwbuf->typeflag == BFTW_DIR) {
- ret = bfs_check_acl_type(path, ACL_TYPE_DEFAULT);
+#if __APPLE__
+ // macOS gives EINVAL for either of the two standard ACL types,
+ // supporting only ACL_TYPE_EXTENDED
+ if (ret <= 0) {
+ ret = bfs_check_acl_type(path, ACL_TYPE_EXTENDED);
if (ret < 0) {
error = errno;
}
}
-
-#ifdef ACL_TYPE_EXTENDED
+#else
if (ret <= 0) {
- ret = bfs_check_acl_type(path, ACL_TYPE_EXTENDED);
+ ret = bfs_check_acl_type(path, ACL_TYPE_ACCESS);
+ if (ret < 0) {
+ error = errno;
+ }
+ }
+
+ if (ret <= 0 && ftwbuf->typeflag == BFTW_DIR) {
+ ret = bfs_check_acl_type(path, ACL_TYPE_DEFAULT);
if (ret < 0) {
error = errno;
}