From owner-freebsd-hackers@FreeBSD.ORG Sat Feb 23 06:00:53 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 592AD16A400 for ; Sat, 23 Feb 2008 06:00:53 +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 EB12613C467 for ; Sat, 23 Feb 2008 06:00:52 +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 m1N5xENV031006 for ; Fri, 22 Feb 2008 22:59:14 -0700 (MST) (envelope-from imp@bsdimp.com) Date: Fri, 22 Feb 2008 22:59:37 -0700 (MST) Message-Id: <20080222.225937.-146245356.imp@bsdimp.com> To: hackers@FreeBSD.ORG From: "M. Warner Losh" 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: 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 06:00:53 -0000 Please find enclosed a patch that implements -lname and -ilname in FreeBSD's find. There's some shell scripts that insist on these gnu findtools features. Comments? Warner 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 05:57:30 -0000 @@ -436,6 +436,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 , @@ -455,6 +459,10 @@ True if the file has .Ar n links. +.It Ic -lname Ar pattern +Like +.Ic -name , +but the 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: 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 22 Feb 2008 19:38:21 -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 liname */ /* 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 22 Feb 2008 19:50:13 -0000 @@ -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; } 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 22 Feb 2008 19:37:33 -0000 @@ -88,7 +88,9 @@ { "-inum", c_inum, f_inum, 0 }, { "-ipath", c_name, f_path, F_IGNCASE }, { "-iregex", c_regex, f_regex, F_IGNCASE }, + { "-liname", c_name, f_name, F_LINK | 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 },