diff options
author | gabor <gabor@FreeBSD.org> | 2011-08-17 13:58:39 +0000 |
---|---|---|
committer | gabor <gabor@FreeBSD.org> | 2011-08-17 13:58:39 +0000 |
commit | cdd0156792a85f1e1ef33dc215e539657b09bb70 (patch) | |
tree | 6610111e999f299ab49ba621a9ef2f2411b76476 /usr.bin/grep | |
parent | 64a3d10a38f6d3b553b3564204cd47e0d08a8f0e (diff) | |
download | FreeBSD-src-cdd0156792a85f1e1ef33dc215e539657b09bb70.zip FreeBSD-src-cdd0156792a85f1e1ef33dc215e539657b09bb70.tar.gz |
- Fix exclusion of directories from a recursive search
- Use FTS_SKIP for exclusion instead of custom code
Submitted by: ttsestt@gmail.com
Approved by: re (kib), delphij (mentor)
Diffstat (limited to 'usr.bin/grep')
-rw-r--r-- | usr.bin/grep/util.c | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c index 683a537..780f0fc 100644 --- a/usr.bin/grep/util.c +++ b/usr.bin/grep/util.c @@ -84,7 +84,7 @@ dir_matching(const char *dname) for (unsigned int i = 0; i < dpatterns; ++i) { if (dname != NULL && - fnmatch(dname, dpattern[i].pat, 0) == 0) { + fnmatch(dpattern[i].pat, dname, 0) == 0) { if (dpattern[i].mode == EXCL_PAT) return (false); else @@ -103,7 +103,6 @@ grep_tree(char **argv) { FTS *fts; FTSENT *p; - char *d, *dir = NULL; int c, fts_flags; bool ok; @@ -135,6 +134,10 @@ grep_tree(char **argv) case FTS_D: /* FALLTHROUGH */ case FTS_DP: + if (dexclude || dinclude) + if (!dir_matching(p->fts_name) || + !dir_matching(p->fts_path)) + fts_set(fts, p, FTS_SKIP); break; case FTS_DC: /* Print a warning for recursive directory loop */ @@ -144,18 +147,6 @@ grep_tree(char **argv) default: /* Check for file exclusion/inclusion */ ok = true; - if (dexclude || dinclude) { - if ((d = strrchr(p->fts_path, '/')) != NULL) { - dir = grep_malloc(sizeof(char) * - (d - p->fts_path + 1)); - memcpy(dir, p->fts_path, - d - p->fts_path); - dir[d - p->fts_path] = '\0'; - } - ok = dir_matching(dir); - free(dir); - dir = NULL; - } if (fexclude || finclude) ok &= file_matching(p->fts_path); |