diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/dirtree.c | 6 | ||||
-rw-r--r-- | lib/lib.c | 5 | ||||
-rw-r--r-- | lib/lib.h | 2 |
3 files changed, 11 insertions, 2 deletions
diff --git a/lib/dirtree.c b/lib/dirtree.c index 45ee139c..a695bb36 100644 --- a/lib/dirtree.c +++ b/lib/dirtree.c @@ -58,6 +58,7 @@ struct dirtree *dirtree_read(char *path, struct dirtree *parent, if (!(dir = opendir(path))) perror_msg("No %s", path); else for (;;) { + int norecurse = 0; struct dirent *entry = readdir(dir); if (!entry) { closedir(dir); @@ -74,8 +75,9 @@ struct dirtree *dirtree_read(char *path, struct dirtree *parent, *ddt = dirtree_add_node(path); if (!*ddt) continue; (*ddt)->parent = parent; - if (callback) callback(path, *ddt); - if (entry->d_type == DT_DIR) + (*ddt)->depth = parent ? parent->depth + 1 : 1; + if (callback) norecurse = callback(path, *ddt); + if (!norecurse && entry->d_type == DT_DIR) (*ddt)->child = dirtree_read(path, *ddt, callback); if (callback) free(*ddt); else ddt = &((*ddt)->next); @@ -326,6 +326,11 @@ char *xabspath(char *path) return path; } +void xchdir(char *path) +{ + if (chdir(path)) error_exit("chdir '%s'"); +} + // Ensure entire path exists. // If mode != -1 set permissions on newly created dirs. // Requires that path string be writable (for temporary null terminators). @@ -36,6 +36,7 @@ void get_optflags(void); struct dirtree { struct dirtree *next, *child, *parent; struct stat st; + int depth; char name[]; }; @@ -75,6 +76,7 @@ void xwrite(int fd, void *buf, size_t len); char *xgetcwd(void); void xstat(char *path, struct stat *st); char *xabspath(char *path); +void xchdir(char *path); void xmkpath(char *path, int mode); struct string_list *find_in_path(char *path, char *filename); void utoa_to_buf(unsigned n, char *buf, unsigned buflen); |