aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/grep
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2018-04-21 13:46:07 +0000
committerKyle Evans <kevans@FreeBSD.org>2018-04-21 13:46:07 +0000
commitff415f05bff4054c1f9b72afb93e67db93b6e890 (patch)
tree8a46eb88d7098b4c4e15ed50375bb20bc2aec28c /usr.bin/grep
parent18f48e0c72f91bc2d4373078a3f1ab1bcab4d8b3 (diff)
downloadsrc-ff415f05bff4054c1f9b72afb93e67db93b6e890.tar.gz
src-ff415f05bff4054c1f9b72afb93e67db93b6e890.zip
bsdgrep: Fix --include/--exclude ordering issues
Prior to r332851: * --exclude always win out over --include * --exclude-dir always wins out over --include-dir r332851 broke that behavior, resulting in: * First of --exclude, --include wins * First of --exclude-dir, --include-dir wins As it turns out, both behaviors are wrong by modern grep standards- the latest rule wins. e.g.: `grep --exclude foo --include foo 'thing' foo` foo is included `grep --include foo --exclude foo 'thing' foo` foo is excluded As tested with GNU grep 3.1. This commit makes bsdgrep follow this behavior. Reported by: se
Notes
Notes: svn path=/head/; revision=332856
Diffstat (limited to 'usr.bin/grep')
-rw-r--r--usr.bin/grep/util.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c
index 557e8d7ab19a..07067a9d3356 100644
--- a/usr.bin/grep/util.c
+++ b/usr.bin/grep/util.c
@@ -109,10 +109,12 @@ file_matching(const char *fname)
for (unsigned int i = 0; i < fpatterns; ++i) {
if (fnmatch(fpattern[i].pat, fname, 0) == 0 ||
- fnmatch(fpattern[i].pat, fname_base, 0) == 0) {
+ fnmatch(fpattern[i].pat, fname_base, 0) == 0)
+ /*
+ * The last pattern matched wins exclusion/inclusion
+ * rights, so we can't reasonably bail out early here.
+ */
ret = (fpattern[i].mode != EXCL_PAT);
- break;
- }
}
free(fname_buf);
return (ret);
@@ -127,7 +129,11 @@ dir_matching(const char *dname)
for (unsigned int i = 0; i < dpatterns; ++i) {
if (dname != NULL && fnmatch(dpattern[i].pat, dname, 0) == 0)
- return (dpattern[i].mode != EXCL_PAT);
+ /*
+ * The last pattern matched wins exclusion/inclusion
+ * rights, so we can't reasonably bail out early here.
+ */
+ ret = (dpattern[i].mode != EXCL_PAT);
}
return (ret);
}