diff options
author | Rob Landley <rob@landley.net> | 2014-07-26 13:30:40 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2014-07-26 13:30:40 -0500 |
commit | fec3fd1f8ac1db9ed87b79bd3eb5e38aa835e881 (patch) | |
tree | a7e149cf0fefef5d252706797fff8c831ebb0460 /lib/dirtree.c | |
parent | ccb73f8bf9191c01c90975958a210c47175bd98c (diff) | |
download | toybox-fec3fd1f8ac1db9ed87b79bd3eb5e38aa835e881.tar.gz |
Move DIRTREE_COMEAGAIN second callback up to when the filehandle is still open, and add dir->again variable to distinguish second call instead of checking for -1 filehandle.
Diffstat (limited to 'lib/dirtree.c')
-rw-r--r-- | lib/dirtree.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/lib/dirtree.c b/lib/dirtree.c index 7ad699e1..8445ca40 100644 --- a/lib/dirtree.c +++ b/lib/dirtree.c @@ -116,8 +116,7 @@ struct dirtree *dirtree_handle_callback(struct dirtree *new, if (dir) { if (flags & (DIRTREE_RECURSE|DIRTREE_COMEAGAIN)) { new->data = openat(dirtree_parentfd(new), new->name, O_CLOEXEC); - dirtree_recurse(new, callback, flags & DIRTREE_SYMFOLLOW); - if (flags & DIRTREE_COMEAGAIN) flags = callback(new); + flags = dirtree_recurse(new, callback, flags); } } @@ -133,8 +132,8 @@ struct dirtree *dirtree_handle_callback(struct dirtree *new, // Recursively read/process children of directory node (with dirfd in data), // filtering through callback(). -void dirtree_recurse(struct dirtree *node, - int (*callback)(struct dirtree *node), int symfollow) +int dirtree_recurse(struct dirtree *node, + int (*callback)(struct dirtree *node), int flags) { struct dirtree *new, **ddt = &(node->child); struct dirent *entry; @@ -146,7 +145,7 @@ void dirtree_recurse(struct dirtree *node, free(path); close(node->data); - return; + return flags; } // according to the fddir() man page, the filehandle in the DIR * can still @@ -154,7 +153,7 @@ void dirtree_recurse(struct dirtree *node, // The extra parentheses are to shut the stupid compiler up. while ((entry = readdir(dir))) { - if (!(new = dirtree_add_node(node, entry->d_name, symfollow))) + if (!(new = dirtree_add_node(node, entry->d_name, flags&DIRTREE_SYMFOLLOW))) continue; new = dirtree_handle_callback(new, callback); if (new == DIRTREE_ABORTVAL) break; @@ -164,9 +163,13 @@ void dirtree_recurse(struct dirtree *node, } } + if (flags & DIRTREE_COMEAGAIN) flags = callback(node); + // This closes filehandle as well, so note it closedir(dir); node->data = -1; + + return flags; } // Create dirtree from path, using callback to filter nodes. |