From c7c8a03a3783cfeb342f033a7cac0dcbe948bbb9 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 26 Nov 2020 21:47:31 -0500 Subject: eval: Make -hidden behave consistently Previously there was an unexpected difference between $ bfs .hidden -hidden and $ bfs ./.hidden -hidden ./.hidden The intent of the code was to avoid considering `.`, the default starting point, as hidden and thus pruning a whole search with -nohidden. Fix it to do that explicitly, and handle `..` too. --- eval.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'eval.c') diff --git a/eval.c b/eval.c index 0503b14..bb93c12 100644 --- a/eval.c +++ b/eval.c @@ -467,7 +467,14 @@ bool eval_fstype(const struct expr *expr, struct eval_state *state) { */ bool eval_hidden(const struct expr *expr, struct eval_state *state) { const struct BFTW *ftwbuf = state->ftwbuf; - return ftwbuf->nameoff > 0 && ftwbuf->path[ftwbuf->nameoff] == '.'; + const char *name = ftwbuf->path + ftwbuf->nameoff; + + // Don't treat "." or ".." as hidden directories. Otherwise we'd filter + // out everything when given + // + // $ bfs . -nohidden + // $ bfs .. -nohidden + return name[0] == '.' && strcmp(name, ".") != 0 && strcmp(name, "..") != 0; } /** -- cgit v1.2.3