Date: Wed, 17 Aug 2011 13:58:39 +0000 (UTC) From: Gabor Kovesdan <gabor@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r224938 - head/usr.bin/grep Message-ID: <201108171358.p7HDwdFp008006@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: gabor Date: Wed Aug 17 13:58:39 2011 New Revision: 224938 URL: http://svn.freebsd.org/changeset/base/224938 Log: - 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) Modified: head/usr.bin/grep/util.c Modified: head/usr.bin/grep/util.c ============================================================================== --- head/usr.bin/grep/util.c Wed Aug 17 13:56:33 2011 (r224937) +++ head/usr.bin/grep/util.c Wed Aug 17 13:58:39 2011 (r224938) @@ -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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201108171358.p7HDwdFp008006>