From owner-freebsd-hackers@FreeBSD.ORG Sat Feb 23 07:03:59 2008 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9204016A400 for ; Sat, 23 Feb 2008 07:03:59 +0000 (UTC) (envelope-from imp@bsdimp.com) Received: from harmony.bsdimp.com (bsdimp.com [199.45.160.85]) by mx1.freebsd.org (Postfix) with ESMTP id 3666813C459 for ; Sat, 23 Feb 2008 07:03:59 +0000 (UTC) (envelope-from imp@bsdimp.com) Received: from localhost (localhost [127.0.0.1]) by harmony.bsdimp.com (8.14.2/8.14.1) with ESMTP id m1N72jW7031450 for ; Sat, 23 Feb 2008 00:02:45 -0700 (MST) (envelope-from imp@bsdimp.com) Date: Sat, 23 Feb 2008 00:03:08 -0700 (MST) Message-Id: <20080223.000308.686168314.imp@bsdimp.com> To: hackers@freebsd.org From: "M. Warner Losh" In-Reply-To: <20080222.225937.-146245356.imp@bsdimp.com> References: <20080222.225937.-146245356.imp@bsdimp.com> X-Mailer: Mew version 5.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Cc: Subject: Re: find -lname and -ilname implemented X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 23 Feb 2008 07:03:59 -0000 Sorry to be lame and follow up to my original email, but Ruslan was way too quick to give me feedback :-) I also did a few more of the really easy ones, and added a list of ones that we haven't implemented yet. Comments? Warner Index: extern.h =================================================================== RCS file: /cache/ncvs/src/usr.bin/find/extern.h,v retrieving revision 1.23 diff -u -r1.23 extern.h --- extern.h 14 May 2006 20:23:00 -0000 1.23 +++ extern.h 23 Feb 2008 06:23:02 -0000 @@ -90,6 +90,7 @@ exec_f f_empty; exec_f f_exec; exec_f f_expr; +exec_f f_false; exec_f f_flags; exec_f f_fstype; exec_f f_group; Index: find.1 =================================================================== RCS file: /cache/ncvs/src/usr.bin/find/find.1,v retrieving revision 1.82 diff -u -r1.82 find.1 --- find.1 28 Feb 2007 10:19:25 -0000 1.82 +++ find.1 23 Feb 2008 06:53:39 -0000 @@ -293,6 +293,12 @@ Please refer to the .Ic -atime primary description for information on supported time units. +.It Ic -d +Same as +.Ic depth . +Gnu find implements this as a primary in mistaken emulation of +.Fx +.Xr find 1 . .It Ic -delete Delete found files and/or directories. Always returns true. @@ -365,6 +371,15 @@ the string .Dq Li {} is not qualified. +.It Ic -execdir Ar utility Oo Ar argument ... Oc Li {} + +Same as +.Ic -execdir , +except that +.Dq Li {} +is replaced with as many pathnames as possible for each invocation of +.Ar utility . +This behaviour is similar to that of +.Xr xargs 1 . .It Ic -flags Oo Cm - Ns | Ns Cm + Oc Ns Ar flags , Ns Ar notflags The flags are specified using symbolic names (see .Xr chflags 1 ) . @@ -436,6 +451,10 @@ is numeric and there is no such group name, then .Ar gname is treated as a group ID. +.It Ic -ilname Ar pattern +Like +.Ic -lname , +but the match is case insensitive. .It Ic -iname Ar pattern Like .Ic -name , @@ -451,10 +470,18 @@ Like .Ic -regex , but the match is case insensitive. +.It Ic -iwholename Ar pattern +The same thing as +.Ic -ipath , +for Gnu find compatibility. .It Ic -links Ar n True if the file has .Ar n links. +.It Ic -lname Ar pattern +Like +.Ic -name , +but the matched file must also be a symbolic link. .It Ic -ls This primary always evaluates to true. The following information for the current file is written to standard output: @@ -497,6 +524,10 @@ .It Ic -mnewer Ar file Same as .Ic -newer . +.It Ic -mount +The same thing as +.Ic -xdev , +for Gnu find compatibility. .It Ic -mtime Ar n Ns Op Cm smhdw If no units are specified, this primary evaluates to true if the difference between the file last modification time and the time @@ -747,6 +778,10 @@ is numeric and there is no such user name, then .Ar uname is treated as a user ID. +.It Ic -wholename Ar pattern +The same thing as +.Ic -path , +for Gnu find compatibility. .El .Pp All primaries which take a numeric argument allow the number to be @@ -770,13 +805,17 @@ true. .Pp .It Cm \&! Ar expression -.It Cm -false Ar expression .It Cm -not Ar expression This is the unary .Tn NOT operator. It evaluates to true if the expression is false. .Pp +.It Cm -false +Always false. +.It Cm -true +Always true. +.Pp .It Ar expression Cm -and Ar expression .It Ar expression expression The Index: find.h =================================================================== RCS file: /cache/ncvs/src/usr.bin/find/find.h,v retrieving revision 1.19 diff -u -r1.19 find.h --- find.h 14 May 2006 20:23:01 -0000 1.19 +++ find.h 23 Feb 2008 06:54:11 -0000 @@ -74,6 +74,7 @@ #define F_EXECPLUS 0x00020000 /* -exec ... {} + */ #define F_TIME_B 0x00040000 /* one of -Btime, -Bnewer, -newerB* */ #define F_TIME2_B 0x00080000 /* one of -newer?B */ +#define F_LINK 0x00100000 /* lname or ilname */ /* node definition */ typedef struct _plandata { Index: function.c =================================================================== RCS file: /cache/ncvs/src/usr.bin/find/function.c,v retrieving revision 1.58 diff -u -r1.58 function.c --- function.c 27 May 2006 18:27:41 -0000 1.58 +++ function.c 23 Feb 2008 06:29:16 -0000 @@ -474,7 +474,7 @@ /* * always_true -- * - * Always true, used for -maxdepth, -mindepth, -xdev and -follow + * Always true, used for -maxdepth, -mindepth, -xdev, -follow, and -true */ int f_always_true(PLAN *plan __unused, FTSENT *entry __unused) @@ -1063,6 +1063,8 @@ int f_name(PLAN *plan, FTSENT *entry) { + if ((plan->flags & F_LINK) && !S_ISLNK(entry->fts_statp->st_mode)) + return 0; return !fnmatch(plan->c_data, entry->fts_name, plan->flags & F_IGNCASE ? FNM_CASEFOLD : 0); } @@ -1076,6 +1078,8 @@ pattern = nextarg(option, argvp); new = palloc(option); new->c_data = pattern; + if (new->flags & F_LINK) + ftsoptions &= ~FTS_NOSTAT; return new; } @@ -1353,7 +1357,7 @@ return new; } -/* c_simple covers c_prune, c_openparen, c_closeparen, c_not, c_or */ +/* c_simple covers c_prune, c_openparen, c_closeparen, c_not, c_or, c_true, c_false */ PLAN * c_simple(OPTION *option, char ***argvp __unused) @@ -1635,3 +1639,16 @@ } /* c_or == c_simple */ + +/* + * -false + * + * Always false. + */ +int +f_false(PLAN *plan __unused, FTSENT *entry __unused) +{ + return 0; +} + +/* c_false == c_simple */ Index: option.c =================================================================== RCS file: /cache/ncvs/src/usr.bin/find/option.c,v retrieving revision 1.25 diff -u -r1.25 option.c --- option.c 5 Apr 2006 23:06:11 -0000 1.25 +++ option.c 23 Feb 2008 06:57:54 -0000 @@ -58,6 +58,7 @@ int typecompare(const void *, const void *); /* NB: the following table must be sorted lexically. */ +/* Options listed with C++ comments are in gnu find, but not our find */ static OPTION const options[] = { { "!", c_simple, f_not, 0 }, { "(", c_simple, f_openparen, 0 }, @@ -74,26 +75,38 @@ { "-cmin", c_Xmin, f_Xmin, F_TIME_C }, { "-cnewer", c_newer, f_newer, F_TIME_C }, { "-ctime", c_Xtime, f_Xtime, F_TIME_C }, + { "-d", c_depth, f_depth, 0 }, +// -daystart { "-delete", c_delete, f_delete, 0 }, { "-depth", c_depth, f_depth, 0 }, { "-empty", c_empty, f_empty, 0 }, { "-exec", c_exec, f_exec, 0 }, { "-execdir", c_exec, f_exec, F_EXECDIR }, - { "-false", c_simple, f_not, 0 }, + { "-false", c_simple, f_false, 0 }, { "-flags", c_flags, f_flags, 0 }, +// -fls { "-follow", c_follow, f_always_true, 0 }, +// -fprint +// -fprint0 +// -fprintf { "-fstype", c_fstype, f_fstype, 0 }, +// -gid { "-group", c_group, f_group, 0 }, +// -ignore_readdir_race + { "-ilname", c_name, f_name, F_LINK | F_IGNCASE }, { "-iname", c_name, f_name, F_IGNCASE }, { "-inum", c_inum, f_inum, 0 }, { "-ipath", c_name, f_path, F_IGNCASE }, { "-iregex", c_regex, f_regex, F_IGNCASE }, + { "-iwholename",c_name, f_path, F_IGNCASE }, { "-links", c_links, f_links, 0 }, + { "-lname", c_name, f_name, F_LINK }, { "-ls", c_ls, f_ls, 0 }, { "-maxdepth", c_mXXdepth, f_always_true, F_MAXDEPTH }, { "-mindepth", c_mXXdepth, f_always_true, 0 }, { "-mmin", c_Xmin, f_Xmin, 0 }, { "-mnewer", c_newer, f_newer, 0 }, + { "-mount", c_xdev, f_always_true, 0 }, { "-mtime", c_Xtime, f_Xtime, 0 }, { "-name", c_name, f_name, 0 }, { "-newer", c_newer, f_newer, 0 }, @@ -118,6 +131,8 @@ { "-newermm", c_newer, f_newer, 0 }, { "-newermt", c_newer, f_newer, F_TIME2_T }, { "-nogroup", c_nogroup, f_nogroup, 0 }, +// -noignore_readdir_race +// -noleaf { "-not", c_simple, f_not, 0 }, { "-nouser", c_nouser, f_nouser, 0 }, { "-o", c_simple, f_or, 0 }, @@ -128,12 +143,19 @@ { "-perm", c_perm, f_perm, 0 }, { "-print", c_print, f_print, 0 }, { "-print0", c_print, f_print0, 0 }, +// -printf { "-prune", c_simple, f_prune, 0 }, +// -quit { "-regex", c_regex, f_regex, 0 }, +// -samefile { "-size", c_size, f_size, 0 }, + { "-true", c_simple, f_always_true, 0 }, { "-type", c_type, f_type, 0 }, +// -uid n { "-user", c_user, f_user, 0 }, + { "-wholename", c_name, f_path, 0 }, { "-xdev", c_xdev, f_always_true, 0 }, +// -xtype }; /*