diff options
author | Rob Landley <rob@landley.net> | 2016-11-21 16:47:23 -0600 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2016-11-21 16:47:23 -0600 |
commit | 382057f588fbf2c2f7950b85dd317721b8d04c07 (patch) | |
tree | ba6b074d5c956f2f5747e27ce0f8ab948a0a602c /lib | |
parent | 9b4a67545e11975068d6e16c6872d54e0473e715 (diff) | |
download | toybox-382057f588fbf2c2f7950b85dd317721b8d04c07.tar.gz |
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.)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/dirtree.c | 13 | ||||
-rw-r--r-- | lib/lib.h | 1 |
2 files changed, 8 insertions, 6 deletions
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); @@ -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); |