GNU bug report logs - #47649
grep bug report - improper handling of file symlinks with -r option

Previous Next

Package: grep;

Reported by: Chris Drake <cryptophoto <at> gmail.com>

Date: Thu, 8 Apr 2021 02:11:01 UTC

Severity: normal

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 47649 in the body.
You can then email your comments to 47649 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-grep <at> gnu.org:
bug#47649; Package grep. (Thu, 08 Apr 2021 02:11:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Chris Drake <cryptophoto <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-grep <at> gnu.org. (Thu, 08 Apr 2021 02:11:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Chris Drake <cryptophoto <at> gmail.com>
To: bug-grep <at> gnu.org
Subject: grep bug report - improper handling of file symlinks with -r option
Date: Thu, 8 Apr 2021 09:46:57 +1000
[Message part 1 (text/plain, inline)]
*This is the original working grep behaviour - it found text inside files
that were symlinks:-*
(Note the output: "*./folder/testfile1:this is my test file*")

[root <at> ir2 ~]# grep --version
grep (GNU grep) 2.5.1

Copyright 1988, 1992-1999, 2000, 2001 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[root <at> ir2 ~]# mkdir bugdemo
[root <at> ir2 ~]# cd bugdemo
[root <at> ir2 bugdemo]# echo "this is my test file" > testfile1
[root <at> ir2 bugdemo]# echo "this is my test file" > testfile2
[root <at> ir2 bugdemo]# mkdir folder
[root <at> ir2 bugdemo]# cd folder
[root <at> ir2 folder]# echo "this is my test file" > testfile3
[root <at> ir2 folder]# ln -s ../testfile1
[root <at> ir2 folder]# cd ..
[root <at> ir2 bugdemo]# unalias grep
[root <at> ir2 bugdemo]# grep -r test .
./testfile2:this is my test file
./folder/testfile1:this is my test file
./folder/testfile3:this is my test file
./testfile1:this is my test file
[root <at> ir2 bugdemo]#


*This is the now-broken current non-working grep behaviour - it fails to
find text inside files that were symlinks:-*
(Note the *missing* output: "*./folder/testfile1:this is my test file*")

[root <at> ir3 ~]# grep --version
grep (GNU grep) 3.1
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html
>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and others, see <
http://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.
[root <at> ir3 ~]# mkdir bugdemo
[root <at> ir3 ~]# cd bugdemo
[root <at> ir3 bugdemo]# echo "this is my test file" > testfile1
[root <at> ir3 bugdemo]# echo "this is my test file" > testfile2
[root <at> ir3 bugdemo]# mkdir folder
[root <at> ir3 bugdemo]# cd folder
[root <at> ir3 folder]# echo "this is my test file" > testfile3
[root <at> ir3 folder]# ln -s ../testfile1
[root <at> ir3 folder]# cd ..
[root <at> ir3 bugdemo]# unalias grep
[root <at> ir3 bugdemo]# grep -r test .
./testfile1:this is my test file
./testfile2:this is my test file
./folder/testfile3:this is my test file
[root <at> ir3 bugdemo]#


It looks like processing exists to not recursively follow symlinks, and
someone has messed with that which has caused files to no longer be
searched by mistake.
[Message part 2 (text/html, inline)]

Information forwarded to bug-grep <at> gnu.org:
bug#47649; Package grep. (Sat, 07 Aug 2021 05:11:01 GMT) Full text and rfc822 format available.

Message #8 received at 47649 <at> debbugs.gnu.org (full text, mbox):

From: Jim Meyering <jim <at> meyering.net>
To: Chris Drake <cryptophoto <at> gmail.com>
Cc: 47649 <at> debbugs.gnu.org
Subject: Re: bug#47649: grep bug report - improper handling of file symlinks
 with -r option
Date: Fri, 6 Aug 2021 22:10:22 -0700
tags 47649 notabug
close 47649
done

On Wed, Apr 7, 2021 at 7:21 PM Chris Drake <cryptophoto <at> gmail.com> wrote:
> *This is the original working grep behaviour - it found text inside files
> that were symlinks:-*
> (Note the output: "*./folder/testfile1:this is my test file*")
>
> [root <at> ir2 ~]# grep --version
> grep (GNU grep) 2.5.1
>
> Copyright 1988, 1992-1999, 2000, 2001 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions. There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
>
> [root <at> ir2 ~]# mkdir bugdemo
> [root <at> ir2 ~]# cd bugdemo
> [root <at> ir2 bugdemo]# echo "this is my test file" > testfile1
> [root <at> ir2 bugdemo]# echo "this is my test file" > testfile2
> [root <at> ir2 bugdemo]# mkdir folder
> [root <at> ir2 bugdemo]# cd folder
> [root <at> ir2 folder]# echo "this is my test file" > testfile3
> [root <at> ir2 folder]# ln -s ../testfile1
> [root <at> ir2 folder]# cd ..
> [root <at> ir2 bugdemo]# unalias grep
> [root <at> ir2 bugdemo]# grep -r test .
> ./testfile2:this is my test file
> ./folder/testfile1:this is my test file
> ./folder/testfile3:this is my test file
> ./testfile1:this is my test file
> [root <at> ir2 bugdemo]#
...
> It looks like processing exists to not recursively follow symlinks, and
> someone has messed with that which has caused files to no longer be
> searched by mistake.

Thanks for the report, but that is the documented behavior of -r.
You appear to prefer -R:

‘-r’
‘--recursive’
     For each directory operand, read and process all files in that
     directory, recursively.  Follow symbolic links on the command line,
     but skip symlinks that are encountered recursively.  Note that if
     no file operand is given, grep searches the working directory.
     This is the same as the ‘--directories=recurse’ option.

‘-R’
‘--dereference-recursive’
     For each directory operand, read and process all files in that
     directory, recursively, following all symbolic links.




Information forwarded to bug-grep <at> gnu.org:
bug#47649; Package grep. (Sat, 07 Aug 2021 13:49:02 GMT) Full text and rfc822 format available.

Message #11 received at 47649 <at> debbugs.gnu.org (full text, mbox):

From: Chris Drake <cryptophoto <at> gmail.com>
To: Jim Meyering <jim <at> meyering.net>
Cc: 47649 <at> debbugs.gnu.org
Subject: Re: bug#47649: grep bug report - improper handling of file symlinks
 with -r option
Date: Sat, 7 Aug 2021 21:43:08 +1000
[Message part 1 (text/plain, inline)]
Hi Jim,

Looks like the -r and -R got mixed up?

What is now the "-R" behaves the same way as the original "-r", and now the
new "-r" behaves differently.

For backwards-compatibility, the original behaviour should have been
preserved, and the new feature assigned to a new switch ?

On Sat, Aug 7, 2021 at 3:10 PM Jim Meyering <jim <at> meyering.net> wrote:

> tags 47649 notabug
> close 47649
> done
>
> On Wed, Apr 7, 2021 at 7:21 PM Chris Drake <cryptophoto <at> gmail.com> wrote:
> > *This is the original working grep behaviour - it found text inside files
> > that were symlinks:-*
> > (Note the output: "*./folder/testfile1:this is my test file*")
> >
> > [root <at> ir2 ~]# grep --version
> > grep (GNU grep) 2.5.1
> >
> > Copyright 1988, 1992-1999, 2000, 2001 Free Software Foundation, Inc.
> > This is free software; see the source for copying conditions. There is NO
> > warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
> PURPOSE.
> >
> > [root <at> ir2 ~]# mkdir bugdemo
> > [root <at> ir2 ~]# cd bugdemo
> > [root <at> ir2 bugdemo]# echo "this is my test file" > testfile1
> > [root <at> ir2 bugdemo]# echo "this is my test file" > testfile2
> > [root <at> ir2 bugdemo]# mkdir folder
> > [root <at> ir2 bugdemo]# cd folder
> > [root <at> ir2 folder]# echo "this is my test file" > testfile3
> > [root <at> ir2 folder]# ln -s ../testfile1
> > [root <at> ir2 folder]# cd ..
> > [root <at> ir2 bugdemo]# unalias grep
> > [root <at> ir2 bugdemo]# grep -r test .
> > ./testfile2:this is my test file
> > ./folder/testfile1:this is my test file
> > ./folder/testfile3:this is my test file
> > ./testfile1:this is my test file
> > [root <at> ir2 bugdemo]#
> ...
> > It looks like processing exists to not recursively follow symlinks, and
> > someone has messed with that which has caused files to no longer be
> > searched by mistake.
>
> Thanks for the report, but that is the documented behavior of -r.
> You appear to prefer -R:
>
> ‘-r’
> ‘--recursive’
>      For each directory operand, read and process all files in that
>      directory, recursively.  Follow symbolic links on the command line,
>      but skip symlinks that are encountered recursively.  Note that if
>      no file operand is given, grep searches the working directory.
>      This is the same as the ‘--directories=recurse’ option.
>
> ‘-R’
> ‘--dereference-recursive’
>      For each directory operand, read and process all files in that
>      directory, recursively, following all symbolic links.
>
[Message part 2 (text/html, inline)]

Information forwarded to bug-grep <at> gnu.org:
bug#47649; Package grep. (Sat, 07 Aug 2021 18:20:02 GMT) Full text and rfc822 format available.

Message #14 received at 47649 <at> debbugs.gnu.org (full text, mbox):

From: Jim Meyering <jim <at> meyering.net>
To: Chris Drake <cryptophoto <at> gmail.com>
Cc: 47649 <at> debbugs.gnu.org
Subject: Re: bug#47649: grep bug report - improper handling of file symlinks
 with -r option
Date: Sat, 7 Aug 2021 11:19:04 -0700
On Sat, Aug 7, 2021 at 4:43 AM Chris Drake <cryptophoto <at> gmail.com> wrote:
> Looks like the -r and -R got mixed up?
>
> What is now the "-R" behaves the same way as the original "-r", and now the new "-r" behaves differently.
>
> For backwards-compatibility, the original behaviour should have been preserved, and the new feature assigned to a new switch ?

Hi Chris,

There was no mix-up, and this is not new.
This was a deliberate decision that dates back to 2012 (first release
with it was 2.12).
Sorry this causes you difficulty, but at least one other grep
implementation has -r and -R options that work this way:

https://www.freebsd.org/cgi/man.cgi?query=grep




bug closed, send any further explanations to 47649 <at> debbugs.gnu.org and Chris Drake <cryptophoto <at> gmail.com> Request was from Paul Eggert <eggert <at> cs.ucla.edu> to control <at> debbugs.gnu.org. (Mon, 09 Aug 2021 10:39:01 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 06 Sep 2021 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 204 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.