Tue 10 Feb 2015 01:45:22 PM UTC, original submission:
When you specify multiple options which must all apply (AND-logic) then for -maxdepth n and -mindepth n, find lately displays a warning, explaining that there are fine points of the order of operations at work -- as if find is using a special form of logic which is something less than boolean. This warning makes no sense at all. For a file to be 'found', ALL of the conditions have to apply. Why would anyone care which one fails first? Specifying multiple AND-conditions for find is the most common use case, and for this use case, without a single OR-condition, the warning is most rudely displayed. Other GNU utilities allow arguments (additional conditions) to be added at the end of the command line, but find has this feature / regression by which it does not do so.
It seems that `find' is trying to warn the uer about the global nature of -maxdepth and -mindepth -- but this warning is entirely unnecessary when the entire find command consists of AND-conditions. All conditions must apply, so none of them apply first.
This spurious warning is a good and proper bug, as evidenced by the slew of bug reports in all sorts of projects since 2006
To reproduce this bug:
find -type f -maxdepth 1 -mindepth 1
Expected behaviour:
print a list of files in the current directory, without spurious warnings.
Incorrect behaviour:
Spurious warnings are printed.
find: warning: you have specified the -mindepth option after a non-option argument -type, but options are not positional (-mindepth affects tests specified before it as well as those specified after it). Please specify options before other arguments.
find: warning: you have specified the -maxdepth option after a non-option argument -type, but options are not positional (-maxdepth affects tests specified before it as well as those specified after it). Please specify options before other arguments.
Proposed fix 1:
Only display this warning when it may indicate a logic bug, e.g. OR-logic is included. (I can't improve this suggestion, since I don't understand circumstances where one would benefit from this warning.)
Proposed fix 2:
Remove this warning as per attached patch :P
(How about this: no warning is showed for "find -maxdepth 1 -print -type d" where "-type d" has no effect ... this is a real error ... unless it was "-type d $ACTION" where $ACTION is null ...)
|