+int reapply_default_acl_nftw(const char *target,
+ const struct stat *s,
+ int info,
+ struct FTW *ftw) {
+ /* A wrapper around the reapply_default_acl() function for use with
+ * nftw(). We need to adjust the return value so that nftw() doesn't
+ * think we've failed.
+ */
+ bool reapp_result = reapply_default_acl(target);
+ if (reapp_result) {
+ return 0;
+ }
+ else {
+ return 1;
+ }
+}
+
+
+bool reapply_default_acl_recursive(const char *target) {
+ /* Attempt to reapply default ACLs recursively. If target is a
+ * directory, we recurse through its entries. If not, we just
+ * reapply the default ACL to target.
+ *
+ * We ignore symlinks for consistency with chmod -r.
+ *
+ */
+ if (!is_directory(target)) {
+ return reapply_default_acl(target);
+ }
+
+ int max_levels = 256;
+ int flags = FTW_PHYS; /* Don't follow links. */
+
+ int nftw_result = nftw(target,
+ reapply_default_acl_nftw,
+ max_levels,
+ flags);
+
+ if (nftw_result == 0) {
+ /* Success */
+ return true;
+ }
+
+ /* nftw will return -1 on error, or if the supplied function
+ * (reapply_default_acl_nftw) returns a non-zero result, nftw will
+ * return that.
+ */
+ if (nftw_result == -1) {
+ perror("reapply_default_acl_recursive (nftw)");
+ }
+
+ return false;
+}
+
+