diff lib/dirtree.c @ 589:7013fd450ff4

Changed my mind about the design again, now callback is dirtree_opennode() and recursion choice is how caller interprets flags.
author Rob Landley <rob@landley.net>
date Fri, 01 Jun 2012 20:27:51 -0500
parents 9c2277b92b86
children fb582378a36a
line wrap: on
line diff
--- a/lib/dirtree.c	Fri Jun 01 20:04:39 2012 -0500
+++ b/lib/dirtree.c	Fri Jun 01 20:27:51 2012 -0500
@@ -78,21 +78,20 @@
 	return DIRTREE_SAVE|DIRTREE_RECURSE;
 }
 
-// depth first recursion
-int dirtree_comeagain(struct dirtree *try, int recurse)
+// get open filehandle for node in extra, giving caller the option of
+// using DIRTREE_COMEAGAIN or not.
+int dirtree_opennode(struct dirtree *try)
 {
-	int ret = dirtree_notdotdot(try);
-	if (ret) {
-		if (S_ISDIR(try->st.st_mode)) {
-			if (!try->extra) {
-				try->extra = xdup(try->data);
-				if (recurse) return DIRTREE_COMEAGAIN;
-			}
-		} else try->extra = openat(try->parent ? try->parent->data : AT_FDCWD,
-			try->name, 0);
-	}
+	if (!dirtree_notdotdot(try)) return 0;
+	if (S_ISDIR(try->st.st_mode)) {
+		if (!try->extra) {
+			try->extra = xdup(try->data);
+			return DIRTREE_COMEAGAIN;
+		}
+	} else try->extra = openat(try->parent ? try->parent->data : AT_FDCWD,
+		try->name, 0);
 
-	return ret;
+	return DIRTREE_SAVE|DIRTREE_RECURSE;
 }
 
 // Handle callback for a node in the tree. Returns saved node(s) or NULL.