grep: -r no longer follows symlinks; use fts
commitc6e3ea61d9f08aa0128a0eb13d31a2fbad376f99
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 10 Mar 2012 19:29:32 +0000 (10 11:29 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 15 Mar 2012 05:28:27 +0000 (14 22:28 -0700)
tree657c6157dd4b4c250a4bbdf770ef62cfb2062571
parent354516cd121a7cdbad1397662b718b04c349692a
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.
12 files changed:
.gitignore
Makefile.boot
NEWS
bootstrap.conf
doc/grep.texi
lib/Makefile.am
lib/savedir.c [deleted file]
lib/savedir.h [deleted file]
po/POTFILES.in
src/main.c
tests/Makefile.am
tests/symlink [new file with mode: 0755]