[PATCH] grep: fix -r following file symlinks
Csókás Bence
csokas.bence at prolan.hu
Mon Apr 14 14:05:46 UTC 2025
Hi,
On 2025. 04. 14. 12:16, Sertonix wrote:
>
> GNU grep -r doesn't search in files that are linked to by symlinks.
>
> function old new delta
> file_action_grep 219 228 +9
> ------------------------------------------------------------------------------
> (add/remove: 0/0 grow/shrink: 1/0 up/down: 9/0) Total: 9 bytes
> ---
> findutils/grep.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/findutils/grep.c b/findutils/grep.c
> index f6d0a73f4..0bd4898bc 100644
> --- a/findutils/grep.c
> +++ b/findutils/grep.c
> @@ -666,6 +666,8 @@ static int FAST_FUNC file_action_grep(struct recursive_state *state UNUSED_PARAM
> * example will return the raw directory contents). */
> if (S_ISLNK(statbuf->st_mode)) {
> struct stat sb;
> + if (!(option_mask32 & OPT_R))
You mixed it up, -R *does* follow links, -r doesn't (which would be
OPT_r here). But the whole patch is not needed anyway, because
recursive_action() (which calls file_action_grep()) only follows
symlinks if -R is given: [1]
[1] https://git.busybox.net/busybox/tree/findutils/grep.c#n696
> + return 0;
> if (stat(filename, &sb) != 0) {
> if (!SUPPRESS_ERR_MSGS)
> bb_simple_perror_msg(filename);
Bence
More information about the busybox
mailing list