From 382057f588fbf2c2f7950b85dd317721b8d04c07 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 21 Nov 2016 16:47:23 -0600 Subject: Have dirtree_notdotdot() pass through !node->parent so . and .. on the command line aren't filtered out. Audited all the callers and removed redundant calls, adjusted call sequence, etc. (And let rm _not_ do this, because posix.) --- lib/dirtree.c | 13 +++++++------ lib/lib.h | 1 + 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/dirtree.c b/lib/dirtree.c index 8f235ed4..07c1cdc7 100644 --- a/lib/dirtree.c +++ b/lib/dirtree.c @@ -5,19 +5,20 @@ #include "toys.h" -static int notdotdot(char *name) +int isdotdot(char *name) { - if (name[0]=='.' && (!name[1] || (name[1]=='.' && !name[2]))) return 0; + if (name[0]=='.' && (!name[1] || (name[1]=='.' && !name[2]))) return 1; - return 1; + return 0; } -// Default callback, filters out "." and "..". +// Default callback, filters out "." and ".." except at top level. int dirtree_notdotdot(struct dirtree *catch) { // Should we skip "." and ".."? - return notdotdot(catch->name)*(DIRTREE_SAVE|DIRTREE_RECURSE); + return (!catch->parent||!isdotdot(catch->name)) + *(DIRTREE_SAVE|DIRTREE_RECURSE); } // Create a dirtree node from a path, with stat and symlink info. @@ -54,7 +55,7 @@ struct dirtree *dirtree_add_node(struct dirtree *parent, char *name, int flags) return dt; error: - if (!(flags&DIRTREE_SHUTUP) && notdotdot(name)) { + if (!(flags&DIRTREE_SHUTUP) && !isdotdot(name)) { char *path = parent ? dirtree_path(parent, 0) : ""; perror_msg("%s%s%s", path, parent ? "/" : "", name); diff --git a/lib/lib.h b/lib/lib.h index 2afe558b..61a1975f 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -88,6 +88,7 @@ struct dirtree { char name[]; }; +int isdotdot(char *name); struct dirtree *dirtree_add_node(struct dirtree *p, char *name, int flags); char *dirtree_path(struct dirtree *node, int *plen); int dirtree_notdotdot(struct dirtree *catch); -- cgit v1.2.3