[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: [PATCH 2 of 2] grep: -r should recurse into symlinks to directories
From:       Denys Vlasenko <vda.linux () googlemail ! com>
Date:       2014-08-28 13:47:36
Message-ID: CAK1hOcPv6Fpf-UJrPQFD5HsFBmCdYAao8O2A7F5gJg6bSgJvZw () mail ! gmail ! com
[Download RAW message or body]

On Tue, Jul 29, 2014 at 10:45 AM, Thomas De Schampheleire
<patrickdepinguin@gmail.com> wrote:
> The command
>     grep -r . symlink_to_dir
> should recurse into the directory pointed to by symlink_to_dir.
> This patch fixes grep to implement this case.
> This also fixes the newly added test in the testsuite.
>
> Signed-off-by: Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
>
> ---
>  findutils/grep.c |  2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff -r 66406add5e60 -r 8c87fa8591be findutils/grep.c
> --- a/findutils/grep.c  Mon Jul 28 16:33:41 2014 +0200
> +++ b/findutils/grep.c  Mon Jul 28 16:38:36 2014 +0200
> @@ -668,7 +668,7 @@
>         int matched = 0;
>         recursive_action(dir,
>                 /* recurse=yes */ ACTION_RECURSE |
> -               /* followLinks=no */
> +               /* followLinks=yes */ ACTION_FOLLOWLINKS |
>                 /* depthFirst=yes */ ACTION_DEPTHFIRST,
>                 /* fileAction= */ file_action_grep,
>                 /* dirAction= */ NULL,
> _______________________________________________
> busybox mailing list
> busybox@busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox


In fact, ACTION_FOLLOWLINKS_L0 is needed.
Applying the following patch:


diff -d -urpN busybox.1/findutils/grep.c busybox.2/findutils/grep.c
--- busybox.1/findutils/grep.c    2014-08-15 13:04:28.000000000 +0200
+++ busybox.2/findutils/grep.c    2014-08-28 15:46:24.499460968 +0200
@@ -668,7 +668,7 @@ static int grep_dir(const char *dir)
     int matched = 0;
     recursive_action(dir,
         /* recurse=yes */ ACTION_RECURSE |
-        /* followLinks=no */
+        /* followLinks=command line only */ ACTION_FOLLOWLINKS_L0 |
         /* depthFirst=yes */ ACTION_DEPTHFIRST,
         /* fileAction= */ file_action_grep,
         /* dirAction= */ NULL,
diff -d -urpN busybox.1/testsuite/grep.tests busybox.2/testsuite/grep.tests
--- busybox.1/testsuite/grep.tests    2014-08-15 13:04:29.000000000 +0200
+++ busybox.2/testsuite/grep.tests    2014-08-28 15:46:15.459420496 +0200
@@ -171,6 +171,26 @@ testing "grep -w word match second word"
     "bword,word\n""wordb,word\n""bwordb,word\n" \
     ""

+# -r on symlink to dir should recurse into dir
+mkdir -p grep.testdir/foo
+echo bar > grep.testdir/foo/file
+ln -s foo grep.testdir/symfoo
+testing "grep -r on symlink to dir" \
+    "grep -r . grep.testdir/symfoo" \
+    "grep.testdir/symfoo/file:bar\n" \
+    "" ""
+rm -Rf grep.testdir
+
+# But -r on dir/symlink_to_dir should not recurse into symlink_to_dir
+mkdir -p grep.testdir/foo
+echo bar > grep.testdir/foo/file
+ln -s foo grep.testdir/symfoo
+testing "grep -r on dir/symlink to dir" \
+    "grep -r . grep.testdir" \
+    "grep.testdir/foo/file:bar\n" \
+    "" ""
+rm -Rf grep.testdir
+
 # testing "test name" "commands" "expected result" "file input" "stdin"
 #   file input will be file called "input"
 #   test can create a file "actual" instead of writing to stdout
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic