diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2012-03-10 11:29:32 -0800 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2012-03-14 22:28:27 -0700 |
commit | c6e3ea61d9f08aa0128a0eb13d31a2fbad376f99 (patch) | |
tree | 657c6157dd4b4c250a4bbdf770ef62cfb2062571 /tests | |
parent | 354516cd121a7cdbad1397662b718b04c349692a (diff) | |
download | grep-c6e3ea61d9f08aa0128a0eb13d31a2fbad376f99.tar.gz |
grep: -r no longer follows symlinks; use fts
Change -r to follow only command-line symlinks, and by default to
read only devices named on the command line. This is a simple
way to get a more-useful behavior when searching random
directories; the idea is to use 'find' if you want something fancy.
-R acts as before and gets a new alias --dereference-recursive.
The code now uses fts internally, so it is more robust and
faster with large hierarchies.
* .gitignore: Remove lib/savedir.c, lib/savedir.h.
* tests/symlink: New file
* Makefile.boot (LIB_OBJS_core): Remove isdir.o, savedir.o.
Perhaps other changes are needed too, but I'm not sure what
this makefile is for.
* NEWS: Document changes.
* doc/grep.texi (File and Directory Selection): Likewise.
* bootstrap.conf (gnulib_modules): Remove dirent, dirname, isdir, open.
Add fstatat, fts, openat-safer.
* lib/Makefile.am (libgreputils_a_SOURCES): Remove savedir.c, savedir.h.
* lib/savedir.c, lib/savedir.h: Remove.
* po/POTFILES.in: Add lib/openat-die.c.
* src/main.c: Include fcntl-safer.h, fts_.h. Don't include
isdir.h, savedir.h.
(struct stats, stats_base): Remove.
(long_options, usage, main): Add --dereference-recursive and
implement -r vs -R.
(filename_prefix_len, fts_options): New static vars.
(basic_fts_options, READ_COMMAND_LINE_DEVICES): New constants.
(devices): Now defaults to READ_COMMAND_LINE_DEVICES.
(reset, grep): Now takes just struct stat rather than file name and
struct stats. All callers changed.
(fillbuf): Now takes struct stat reather than struct stats.
All callers changed.
(grep): Don't worry about recursing too deeply; fts and grepdesc
handle this now.
(is_device_mode, grepdirent, grepdesc, grep_command_line_args):
New functions.
(grepfile): New args DIRDESC, FOLLOW, COMMAND_LINE. Remove struct stats
arg. All callers changed. Use openat_safer rather than open.
Use desc == STDIN_FILENO to tell whether we're reading "-".
Don't worry about EINTR when closing -- not possible, since we're
not catching signals.
* tests/Makefile.am (TESTS): Add symlink.
* tests/symlink: New file.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rwxr-xr-x | tests/symlink | 65 |
2 files changed, 66 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index c2cd2f7d..13061fed 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -82,6 +82,7 @@ TESTS = \ spencer1 \ spencer1-locale \ status \ + symlink \ turkish-I \ warn-char-classes \ word-delim-multibyte \ diff --git a/tests/symlink b/tests/symlink new file mode 100755 index 00000000..012d8f8f --- /dev/null +++ b/tests/symlink @@ -0,0 +1,65 @@ +#!/bin/sh +# Check that "grep -r" does the right thing with symbolic links. + +# Copyright (C) 2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# written by Paul Eggert + +. "${srcdir=.}/init.sh"; path_prepend_ ../src + +mkdir dir || framework_failure_ +echo a > dir/a || framework_failure_ +echo b > dir/b || framework_failure_ +ln -s a dir/c || framework_failure_ +ln -s . dir/d || framework_failure_ +ln -s dangling dir/e || framework_failure_ + +touch out || framework_failure_ + +for recursion in '' -r -R +do + for files in '' '*' + do + case $recursion,$files in + -R,* | *,'*') expected_status=2 ;; + *) expected_status=0 ;; + esac + + (cd dir && grep $recursion '^' $files <a ) >grepout + test $? -eq $expected_status || fail=1 + + case $recursion,$files in + ,) + exp='a\n' ;; + ,'*' | -R,) + exp='a:a\nb:b\nc:a\n' ;; + -r,) + exp='a:a\nb:b\n' ;; + -r,'*') + exp='a:a\nb:b\nc:a\nd/a:a\nd/b:b\n' ;; + -R,'*') + exp='a:a\nb:b\nc:a\nd/a:a\nd/b:b\nd/c:a\n' ;; + *) + framework_failure_ ;; + esac + + printf "$exp" >exp || framework_failure_ + LC_ALL=C sort grepout >out || fail=1 + compare exp out || fail=1 + done +done + +Exit $fail |