grep: fix "grep -r PATTRN SYMLINK_TO_DIR"
authorDenys Vlasenko <vda.linux@googlemail.com>
Thu, 28 Aug 2014 13:50:09 +0000 (15:50 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Thu, 28 Aug 2014 13:50:09 +0000 (15:50 +0200)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
findutils/grep.c
testsuite/grep.tests

index f1b6dc694f41d983e6601c7c5bdd0829ec0ed479..b9621384ec78e5054d4b04dc4d5addf123f1af0a 100644 (file)
@@ -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,
index 323b3849dea4982fad70f5de458a7daf57fc676a..f6d9f2105204a0bc8e6cbf41c56b14161672e1a0 100755 (executable)
@@ -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