aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/dirtree.c12
-rw-r--r--lib/lib.h17
2 files changed, 15 insertions, 14 deletions
diff --git a/lib/dirtree.c b/lib/dirtree.c
index aa3ab76b..25248f5d 100644
--- a/lib/dirtree.c
+++ b/lib/dirtree.c
@@ -68,14 +68,14 @@ char *dirtree_path(struct dirtree *node, int *plen)
// Default callback, filters out "." and "..".
-int dirtree_isdotdot(struct dirtree *catch)
+int dirtree_notdotdot(struct dirtree *catch)
{
// Should we skip "." and ".."?
if (catch->name[0]=='.' && (!catch->name[1] ||
(catch->name[1]=='.' && !catch->name[2])))
- return DIRTREE_NOSAVE|DIRTREE_NORECURSE;
+ return 0;
- return 0;
+ return DIRTREE_SAVE|DIRTREE_RECURSE;
}
// Handle callback for a node in the tree. Returns saved node(s) or NULL.
@@ -91,11 +91,11 @@ struct dirtree *handle_callback(struct dirtree *new,
{
int flags;
- if (!callback) callback = dirtree_isdotdot;
+ if (!callback) callback = dirtree_notdotdot;
flags = callback(new);
if (S_ISDIR(new->st.st_mode)) {
- if (!(flags & DIRTREE_NORECURSE)) {
+ if (flags & DIRTREE_RECURSE) {
new->data = openat (new->parent ? new->parent->data : AT_FDCWD,
new->name, 0);
dirtree_recurse(new, callback);
@@ -104,7 +104,7 @@ struct dirtree *handle_callback(struct dirtree *new,
if (flags & DIRTREE_COMEAGAIN) flags = callback(new);
}
// If this had children, it was callback's job to free them already.
- if (flags & DIRTREE_NOSAVE) {
+ if (!(flags & DIRTREE_SAVE)) {
free(new);
new = NULL;
}
diff --git a/lib/lib.h b/lib/lib.h
index 812908af..b5292b85 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -48,16 +48,17 @@ void get_optflags(void);
// Values returnable from callback function (bitfield, or them together)
// Default with no callback is 0
-// Do not add this node to the tree
-#define DIRTREE_NOSAVE 1
-// Do not recurse into children
-#define DIRTREE_NORECURSE 2
-// Call again after handling all children (Directories only. Sets linklen = -1)
+// Add this node to the tree
+#define DIRTREE_SAVE 1
+// Recurse into children
+#define DIRTREE_RECURSE 2
+// Call again after handling all children of this directory
+// (Ignored for non-directories, sets linklen = -1 before second call.)
#define DIRTREE_COMEAGAIN 4
// Follow symlinks to directories
#define DIRTREE_SYMFOLLOW 8
-// Abort recursive dirtree. (Forces NOSAVE and NORECURSE on this entry.)
-#define DIRTREE_ABORT (256|DIRTREE_NOSAVE|DIRTREE_NORECURSE)
+// Don't look at any more files in this directory.
+#define DIRTREE_ABORT 256
#define DIRTREE_ABORTVAL ((struct dirtree *)1)
@@ -72,7 +73,7 @@ struct dirtree {
struct dirtree *dirtree_add_node(int dirfd, char *name);
char *dirtree_path(struct dirtree *node, int *plen);
-int dirtree_isdotdot(struct dirtree *catch);
+int dirtree_notdotdot(struct dirtree *catch);
struct dirtree *handle_callback(struct dirtree *new,
int (*callback)(struct dirtree *node));
void dirtree_recurse(struct dirtree *node,