Mercurial > hg > toybox
changeset 258:e64dec29965d
Dirtree needs to use lstat(), not stat. And failure should probably be a
warning rather than an error (it means the directory tree is changing out
from under it, but only the user knows if that's fatal).
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 16 Feb 2008 19:41:20 -0600 |
parents | 951110c37fee |
children | b4fec0865d8e |
files | lib/dirtree.c |
diffstat | 1 files changed, 8 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/dirtree.c Tue Feb 12 19:05:44 2008 -0600 +++ b/lib/dirtree.c Sat Feb 16 19:41:20 2008 -0600 @@ -6,6 +6,8 @@ #include "toys.h" +// NOTE: This uses toybuf. Possibly it shouldn't do that. + // Create a dirtree node from a path. struct dirtree *dirtree_add_node(char *path) @@ -30,7 +32,11 @@ } dt = xzalloc(sizeof(struct dirtree)+strlen(name)+1); - xstat(path, &(dt->st)); + if (lstat(path, &(dt->st))) { + error_msg("Skipped '%s'",name); + free(dt); + return 0; + } strcpy(dt->name, name); return dt; @@ -64,6 +70,7 @@ snprintf(path+len, sizeof(toybuf)-len, "/%s", entry->d_name); *ddt = dirtree_add_node(path); + if (!*ddt) continue; (*ddt)->parent = parent; if (callback) callback(*ddt); if (entry->d_type == DT_DIR)