diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/dirtree.c | 12 | ||||
-rw-r--r-- | lib/lib.h | 2 |
2 files changed, 6 insertions, 8 deletions
diff --git a/lib/dirtree.c b/lib/dirtree.c index cc1ab90c..8f235ed4 100644 --- a/lib/dirtree.c +++ b/lib/dirtree.c @@ -110,12 +110,9 @@ struct dirtree *dirtree_handle_callback(struct dirtree *new, if (!callback) return new; flags = callback(new); - if (S_ISDIR(new->st.st_mode)) { - if (flags & (DIRTREE_RECURSE|DIRTREE_COMEAGAIN)) { - new->dirfd = openat(dirtree_parentfd(new), new->name, O_CLOEXEC); - flags = dirtree_recurse(new, callback, flags); - } - } + if (S_ISDIR(new->st.st_mode) && (flags & (DIRTREE_RECURSE|DIRTREE_COMEAGAIN))) + flags = dirtree_recurse(new, callback, + openat(dirtree_parentfd(new), new->name, O_CLOEXEC), flags); // If this had children, it was callback's job to free them already. if (!(flags & DIRTREE_SAVE)) { @@ -130,12 +127,13 @@ struct dirtree *dirtree_handle_callback(struct dirtree *new, // callback(). Uses and closes supplied ->dirfd. int dirtree_recurse(struct dirtree *node, - int (*callback)(struct dirtree *node), int flags) + int (*callback)(struct dirtree *node), int dirfd, int flags) { struct dirtree *new, **ddt = &(node->child); struct dirent *entry; DIR *dir; + node->dirfd = dirfd; if (node->dirfd == -1 || !(dir = fdopendir(node->dirfd))) { if (!(flags & DIRTREE_SHUTUP)) { char *path = dirtree_path(node, 0); @@ -84,7 +84,7 @@ char *dirtree_path(struct dirtree *node, int *plen); int dirtree_notdotdot(struct dirtree *catch); int dirtree_parentfd(struct dirtree *node); int dirtree_recurse(struct dirtree *node, int (*callback)(struct dirtree *node), - int symfollow); + int dirfd, int symfollow); struct dirtree *dirtree_flagread(char *path, int flags, int (*callback)(struct dirtree *node)); struct dirtree *dirtree_read(char *path, int (*callback)(struct dirtree *node)); |