comparison 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
comparison
equal deleted inserted replaced
588:9c2277b92b86 589:7013fd450ff4
76 return 0; 76 return 0;
77 77
78 return DIRTREE_SAVE|DIRTREE_RECURSE; 78 return DIRTREE_SAVE|DIRTREE_RECURSE;
79 } 79 }
80 80
81 // depth first recursion 81 // get open filehandle for node in extra, giving caller the option of
82 int dirtree_comeagain(struct dirtree *try, int recurse) 82 // using DIRTREE_COMEAGAIN or not.
83 int dirtree_opennode(struct dirtree *try)
83 { 84 {
84 int ret = dirtree_notdotdot(try); 85 if (!dirtree_notdotdot(try)) return 0;
85 if (ret) { 86 if (S_ISDIR(try->st.st_mode)) {
86 if (S_ISDIR(try->st.st_mode)) { 87 if (!try->extra) {
87 if (!try->extra) { 88 try->extra = xdup(try->data);
88 try->extra = xdup(try->data); 89 return DIRTREE_COMEAGAIN;
89 if (recurse) return DIRTREE_COMEAGAIN; 90 }
90 } 91 } else try->extra = openat(try->parent ? try->parent->data : AT_FDCWD,
91 } else try->extra = openat(try->parent ? try->parent->data : AT_FDCWD, 92 try->name, 0);
92 try->name, 0);
93 }
94 93
95 return ret; 94 return DIRTREE_SAVE|DIRTREE_RECURSE;
96 } 95 }
97 96
98 // Handle callback for a node in the tree. Returns saved node(s) or NULL. 97 // Handle callback for a node in the tree. Returns saved node(s) or NULL.
99 // 98 //
100 // By default, allocates a tree of struct dirtree, not following symlinks 99 // By default, allocates a tree of struct dirtree, not following symlinks