Mercurial > hg > toybox
comparison lib/dirtree.c @ 320:7259b853cb8b
Work around a reiserfs bug. (One line change, switch from looking at broken struct dirent->dt_type to looking at stat() output. The rest are unrelated variable renames.)
author | Rob Landley <rob@landley.net> |
---|---|
date | Wed, 12 Nov 2008 18:01:35 -0600 |
parents | b4077be6c746 |
children | 44abf4d901f3 |
comparison
equal
deleted
inserted
replaced
319:d5b8d286c8d1 | 320:7259b853cb8b |
---|---|
50 // structures after use, and return NULL. | 50 // structures after use, and return NULL. |
51 | 51 |
52 struct dirtree *dirtree_read(char *path, struct dirtree *parent, | 52 struct dirtree *dirtree_read(char *path, struct dirtree *parent, |
53 int (*callback)(char *path, struct dirtree *node)) | 53 int (*callback)(char *path, struct dirtree *node)) |
54 { | 54 { |
55 struct dirtree *dt = NULL, **ddt = &dt; | 55 struct dirtree *dtroot = NULL, *this, **ddt = &dtroot; |
56 DIR *dir; | 56 DIR *dir; |
57 int len = strlen(path); | 57 int len = strlen(path); |
58 | 58 |
59 if (!(dir = opendir(path))) perror_msg("No %s", path); | 59 if (!(dir = opendir(path))) perror_msg("No %s", path); |
60 else for (;;) { | 60 else for (;;) { |
70 if (!entry->d_name[1]) continue; | 70 if (!entry->d_name[1]) continue; |
71 if (entry->d_name[1]=='.' && !entry->d_name[2]) continue; | 71 if (entry->d_name[1]=='.' && !entry->d_name[2]) continue; |
72 } | 72 } |
73 | 73 |
74 snprintf(path+len, sizeof(toybuf)-len, "/%s", entry->d_name); | 74 snprintf(path+len, sizeof(toybuf)-len, "/%s", entry->d_name); |
75 *ddt = dirtree_add_node(path); | 75 *ddt = this = dirtree_add_node(path); |
76 if (!*ddt) continue; | 76 if (!this) continue; |
77 (*ddt)->parent = parent; | 77 this->parent = parent; |
78 (*ddt)->depth = parent ? parent->depth + 1 : 1; | 78 this->depth = parent ? parent->depth + 1 : 1; |
79 if (callback) norecurse = callback(path, *ddt); | 79 if (callback) norecurse = callback(path, this); |
80 if (!norecurse && entry->d_type == DT_DIR) | 80 if (!norecurse && S_ISDIR(this->st.st_mode)) |
81 (*ddt)->child = dirtree_read(path, *ddt, callback); | 81 this->child = dirtree_read(path, this, callback); |
82 if (callback) free(*ddt); | 82 if (callback) free(this); |
83 else ddt = &((*ddt)->next); | 83 else ddt = &(this->next); |
84 path[len]=0; | 84 path[len]=0; |
85 } | 85 } |
86 | 86 |
87 return dt; | 87 return dtroot; |
88 } | 88 } |
89 | 89 |
90 | 90 |