Date: Thu, 13 May 2004 18:39:31 +0200 From: Oliver Eikemeier <eikemeier@fillmore-labs.com> To: FreeBSD-gnats-submit@FreeBSD.org Subject: bin/66613: find(1): -mindepth and -maxdepth doesn't work as expected Message-ID: <40A3A4C3.5000604@fillmore-labs.com> Resent-Message-ID: <200405131640.i4DGeKMB030011@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 66613 >Category: bin >Synopsis: find(1): -mindepth and -maxdepth doesn't work as expected >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Thu May 13 09:40:20 PDT 2004 >Closed-Date: >Last-Modified: >Originator: Oliver Eikemeier >Release: FreeBSD 4.10-STABLE i386 >Organization: Fillmore Labs - http://www.fillmore-labs.com >Environment: System: FreeBSD nuuk.fillmore-labs.com 4.10-STABLE >Description: find(1) evaluates the primaries -maxdepth and -mindepth in a global context, before the tree traversal begins, and not on a file level as documented. >How-To-Repeat: The manpage find(1) contains the following flags under PRIMARIES: -maxdepth n True if the depth of the current file into the tree is less than or equal to n. -mindepth n True if the depth of the current file into the tree is greater than or equal to n. Assuming that they are evaluated in the expression (as documented) I tried find /usr/ports -name Tools -prune -o -mindepth 2 -maxdepth 2 -type d -print to print all sencond-level directories under ports excluding Tools. /usr/ports/Tools/portbuild /usr/ports/Tools/scripts where listed in the output. Looking at the source and comparing FreeBSD's find implementation with these of other OSs, I realized that this was actually an expectation bug. >Fix: -maxdepth and -mindepth are global flags, and should be documented as such. The example above is equivalent to find /usr/ports -mindepth 2 -maxdepth 2 \( -name Tools -prune -o -type d -print \) See also STANDARDS of find(1), where this behaviour is documented for -depth, -follow and -xdev: Historically, the -d, -H and -x options were implemented using the pri- maries -depth, -follow, and -xdev. These primaries always evaluated to true. As they were really global variables that took effect before the traversal began, some legal expressions could have unexpected results. An example is the expression -print -o -depth. As -print always evalu- ates to true, the standard order of evaluation implies that -depth would never be evaluated. This is not the case. They should read something like: -maxdepth n Always true; parsed before expression is evaluated. Descend at most n directory levels below the command line arguments. -maxdepth 0 limits the whole search to the command line arguments. -mindepth n Always true; parsed before expression is evaluated. Do not apply any tests or actions at levels less than n. -mindepth 1 processes all but the command line arguments. Where expression refers to the parameter in the usage line. If this is acceptable, I will submit a patch against find.1 >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?40A3A4C3.5000604>