aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2008-02-16 19:41:20 -0600
committerRob Landley <rob@landley.net>2008-02-16 19:41:20 -0600
commit7bc7971c0b876b2074ede82327edeaaffa56eb01 (patch)
treed840ea832c3e3f5d7f10d9550bffd244e385ba1e /lib
parent0f8c4c5998317e575f1afd47dad7f6967bc271ab (diff)
downloadtoybox-7bc7971c0b876b2074ede82327edeaaffa56eb01.tar.gz
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).
Diffstat (limited to 'lib')
-rw-r--r--lib/dirtree.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/dirtree.c b/lib/dirtree.c
index d56a5dcb..71f64493 100644
--- a/lib/dirtree.c
+++ b/lib/dirtree.c
@@ -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 @@ struct dirtree *dirtree_add_node(char *path)
}
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 @@ struct dirtree *dirtree_read(char *path, struct dirtree *parent,
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)