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

List:       busybox
Subject:    Re: [PATCH] Add grep -R
From:       Denys Vlasenko <vda.linux () googlemail ! com>
Date:       2019-11-27 15:44:48
Message-ID: CAK1hOcO1qg83hui5xqtZUMw1wu3xGntqx=dECzG-D+fWzCsJjw () mail ! gmail ! com
[Download RAW message or body]

Applied, thanks

On Mon, Nov 25, 2019 at 6:15 PM Tomi Leppänen <tomi.leppanen@jolla.com> wrote:
>
> From: Tomi Leppanen <tomi.leppanen@jolla.com>
>
> This adds -R option to grep similar to GNU grep. It is the same as -r
> but also dereferences symbolic links to directories.
>
> Signed-off-by: Tomi Leppänen <tomi.leppanen@jolla.com>
> ---
>  findutils/grep.c | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/findutils/grep.c b/findutils/grep.c
> index 2cbe7ea91..2d2b69686 100644
> --- a/findutils/grep.c
> +++ b/findutils/grep.c
> @@ -60,7 +60,7 @@
>
>  /* options */
>  //usage:#define grep_trivial_usage
> -//usage:       "[-HhnlLoqvsriwFE"
> +//usage:       "[-HhnlLoqvsrRiwFE"
>  //usage:       IF_EXTRA_COMPAT("z")
>  //usage:       "] [-m N] "
>  //usage:       IF_FEATURE_GREP_CONTEXT("[-A/B/C N] ")
> @@ -78,6 +78,7 @@
>  //usage:     "\n       -v      Select non-matching lines"
>  //usage:     "\n       -s      Suppress open and read errors"
>  //usage:     "\n       -r      Recurse"
> +//usage:     "\n       -R      Recurse and dereference symlinks"
>  //usage:     "\n       -i      Ignore case"
>  //usage:     "\n       -w      Match whole words only"
>  //usage:     "\n       -x      Match whole lines only"
> @@ -108,7 +109,7 @@
>
>  /* -e,-f are lists; -m,-A,-B,-C have numeric param */
>  #define OPTSTR_GREP \
> -       "lnqvscFiHhe:*f:*Lorm:+wx" \
> +       "lnqvscFiHhe:*f:*LorRm:+wx" \
>         IF_FEATURE_GREP_CONTEXT("A:+B:+C:+") \
>         "E" \
>         IF_EXTRA_COMPAT("z") \
> @@ -131,6 +132,7 @@ enum {
>         OPTBIT_L, /* list unmatched file names only */
>         OPTBIT_o, /* show only matching parts of lines */
>         OPTBIT_r, /* recurse dirs */
> +       OPTBIT_R, /* recurse dirs and symlinks to dirs */
>         OPTBIT_m, /* -m MAX_MATCHES */
>         OPTBIT_w, /* -w whole word match */
>         OPTBIT_x, /* -x whole line match */
> @@ -154,6 +156,7 @@ enum {
>         OPT_L = 1 << OPTBIT_L,
>         OPT_o = 1 << OPTBIT_o,
>         OPT_r = 1 << OPTBIT_r,
> +       OPT_R = 1 << OPTBIT_R,
>         OPT_m = 1 << OPTBIT_m,
>         OPT_w = 1 << OPTBIT_w,
>         OPT_x = 1 << OPTBIT_x,
> @@ -682,11 +685,12 @@ static int FAST_FUNC file_action_grep(const char *filename,
>         return 1;
>  }
>
> -static int grep_dir(const char *dir)
> +static int grep_dir(const char *dir, bool deref_symlinks)
>  {
>         int matched = 0;
>         recursive_action(dir,
>                 /* recurse=yes */ ACTION_RECURSE |
> +               /* followLinks=always */ (deref_symlinks ? ACTION_FOLLOWLINKS : 0) |
>                 /* followLinks=command line only */ ACTION_FOLLOWLINKS_L0 |
>                 /* depthFirst=yes */ ACTION_DEPTHFIRST,
>                 /* fileAction= */ file_action_grep,
> @@ -827,12 +831,12 @@ int grep_main(int argc UNUSED_PARAM, char **argv)
>                 if (!cur_file || LONE_DASH(cur_file)) {
>                         cur_file = "(standard input)";
>                 } else {
> -                       if (option_mask32 & OPT_r) {
> +                       if (option_mask32 & (OPT_r|OPT_R)) {
>                                 struct stat st;
>                                 if (stat(cur_file, &st) == 0 && S_ISDIR(st.st_mode)) {
>                                         if (!(option_mask32 & OPT_h))
>                                                 print_filename = 1;
> -                                       matched += grep_dir(cur_file);
> +                                       matched += grep_dir(cur_file, option_mask32 & OPT_R);
>                                         goto grep_done;
>                                 }
>                         }
> --
> 2.23.0
>
> _______________________________________________
> busybox mailing list
> busybox@busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox
_______________________________________________
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