diff options
| author | Bernhard Voelker <mail@bernhard-voelker.de> | 2018-12-26 10:47:11 +0100 |
|---|---|---|
| committer | Bernhard Voelker <mail@bernhard-voelker.de> | 2019-01-05 12:57:11 +0100 |
| commit | 66174c10c617a1a50fa804c1e2f9c6becd7c90f8 (patch) | |
| tree | a4e6d4629ef99fbdfc4fcd5d44b846e7c74639fb | |
| parent | 04f1fbee5d809bc4e51292062174ded768355b58 (diff) | |
| download | findutils-66174c10c6.tar.gz | |
find: improve warning diagnostic for the -name/-iname with '/' in pattern
* find/parser.c (check_name_arg): Add parameter ALT for the alternative
option to suggest. Avoid confusing quoting in the warning by making
the message more terse.
(parse_iname): Pass "-iwholename" as alternative parameter.
(parse_name): Pass "-wholename" as alternative parameter.
Reported by Andreas Metzler in
https://sv.gnu.org/bugs/?55272
| -rw-r--r-- | find/parser.c | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/find/parser.c b/find/parser.c index ae456dd..a3b9e76 100644 --- a/find/parser.c +++ b/find/parser.c @@ -1257,20 +1257,18 @@ fnmatch_sanitycheck (void) static bool -check_name_arg (const char *pred, const char *arg) +check_name_arg (const char *pred, const char *alt, const char *arg) { if (should_issue_warnings () && strchr (arg, '/')) { - error (0, 0,_("warning: Unix filenames usually don't contain slashes " - "(though pathnames do). That means that '%s %s' will " - "probably evaluate to false all the time on this system. " - "You might find the '-wholename' test more useful, or " - "perhaps '-samefile'. Alternatively, if you are using " - "GNU grep, you could " - "use 'find ... -print0 | grep -FzZ %s'."), - pred, - safely_quote_err_filename (0, arg), - safely_quote_err_filename (1, arg)); + error (0, 0, + _("warning: %s matches against basenames only, " + "but the given pattern contains a directory separator (%s), " + "thus the expression will evaluate to false all the time. " + "Did you mean %s?"), + safely_quote_err_filename (0, pred), + safely_quote_err_filename (1, "/"), + safely_quote_err_filename (2, alt)); } return true; /* allow it anyway */ } @@ -1284,7 +1282,7 @@ parse_iname (const struct parser_table* entry, char **argv, int *arg_ptr) fnmatch_sanitycheck (); if (collect_arg (argv, arg_ptr, &name)) { - if (check_name_arg ("-iname", name)) + if (check_name_arg ("-iname", "-iwholename", name)) { struct predicate *our_pred = insert_primary (entry, name); our_pred->need_stat = our_pred->need_type = false; @@ -1471,7 +1469,7 @@ parse_name (const struct parser_table* entry, char **argv, int *arg_ptr) if (collect_arg (argv, arg_ptr, &name)) { fnmatch_sanitycheck (); - if (check_name_arg ("-name", name)) + if (check_name_arg ("-name", "-wholename", name)) { struct predicate *our_pred = insert_primary (entry, name); our_pred->need_stat = our_pred->need_type = false; |
