changeset 14038:597d3800949a

3795 find does not support -path or -ipath Reviewed by: Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org> Reviewed by: Albert Lee <trisk@nexenta.com> Approved by: Dan McDonald <danmcd@nexenta.com>
author Andy Stormont <andyjstormont@gmail.com>
date Wed, 05 Jun 2013 11:48:52 -0400
parents baba481b7c03
children 6cfd5a5778b9
files usr/src/cmd/find/find.c usr/src/man/man1/find.1
diffstat 2 files changed, 42 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/find/find.c	Tue Jun 04 21:56:35 2013 +0200
+++ b/usr/src/cmd/find/find.c	Wed Jun 05 11:48:52 2013 -0400
@@ -21,6 +21,7 @@
 /*
  * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
  * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
+ * Copyright (c) 2013 Andrew Stormont.  All rights reserved.
  */
 
 
@@ -83,10 +84,10 @@
 {
 	PRINT,
 	ACL, AMIN, AND, ATIME, CMIN, CPIO, CSIZE, CTIME, DEPTH, EXEC, F_GROUP,
-	F_GROUPACL, F_USER, F_USERACL, FOLLOW, FSTYPE, INAME, INUM, IREGEX,
-	LINKS, LOCAL, LPAREN, LS, MAXDEPTH, MINDEPTH, MMIN, MOUNT, MTIME, NAME,
-	NCPIO, NEWER, NOGRP, NOT, NOUSER, OK, OR, PERM, PRINT0, PRUNE, REGEX,
-	RPAREN, SIZE, TYPE, VARARGS, XATTR
+	F_GROUPACL, F_USER, F_USERACL, FOLLOW, FSTYPE, INAME, INUM, IPATH,
+	IREGEX,	LINKS, LOCAL, LPAREN, LS, MAXDEPTH, MINDEPTH, MMIN, MOUNT,
+	MTIME, NAME, NCPIO, NEWER, NOGRP, NOT, NOUSER, OK, OR, PATH, PERM,
+	PRINT0, PRUNE, REGEX, RPAREN, SIZE, TYPE, VARARGS, XATTR
 };
 
 enum Type
@@ -125,6 +126,7 @@
 	"-groupacl",	F_GROUPACL,	Num,
 	"-iname",	INAME,		Str,
 	"-inum",	INUM,		Num,
+	"-ipath",	IPATH,		Str,
 	"-iregex",	IREGEX,		Str,
 	"-links",	LINKS,		Num,
 	"-local",	LOCAL,		Unary,
@@ -143,6 +145,7 @@
 	"-o",		OR,		Op,
 	"-ok",		OK,		Exec,
 	"-or",		OR,		Op,
+	"-path",	PATH,		Str,
 	"-perm",	PERM,		Num,
 	"-print",	PRINT,		Unary,
 	"-print0",	PRINT0,		Unary,
@@ -621,6 +624,8 @@
 
 		case NAME:
 		case INAME:
+		case PATH:
+		case IPATH:
 			np->first.cp = b;
 			break;
 		case REGEX:
@@ -993,16 +998,20 @@
 			break;
 
 		case NAME:
-		case INAME: {
-			char *name1;
-			int fnmflags = (np->action == INAME) ?
-			    FNM_IGNORECASE : 0;
+		case INAME:
+		case PATH:
+		case IPATH: {
+			char *path;
+			int fnmflags = 0;
+
+			if (np->action == INAME || np->action == IPATH)
+				fnmflags = FNM_IGNORECASE;
 
 			/*
 			 * basename(3c) may modify name, so
 			 * we need to pass another string
 			 */
-			if ((name1 = strdup(name)) == NULL) {
+			if ((path = strdup(name)) == NULL) {
 				(void) fprintf(stderr,
 				    gettext("%s: cannot strdup() %s: %s\n"),
 				    cmdname, name, strerror(errno));
@@ -1018,8 +1027,11 @@
 #ifndef XPG4
 			fnmflags |= FNM_PERIOD;
 #endif
-			val = !fnmatch(np->first.cp, basename(name1), fnmflags);
-			free(name1);
+
+			val = !fnmatch(np->first.cp,
+			    (np->action == NAME || np->action == INAME)
+				? basename(path) : path, fnmflags);
+			free(path);
 			break;
 		}
 
--- a/usr/src/man/man1/find.1	Tue Jun 04 21:56:35 2013 +0200
+++ b/usr/src/man/man1/find.1	Wed Jun 05 11:48:52 2013 -0400
@@ -2,6 +2,7 @@
 .\" Copyright 1989 AT&T
 .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved
 .\" Copyright 2011 Nexenta Systems, Inc. All rights reserved.
+.\" Copyright (c) 2013 Andrew Stormont.  All rights reserved.
 .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved
 .\"
 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
@@ -312,6 +313,15 @@
 .sp
 .ne 2
 .na
+\fB\fB-ipath\fR \fIpattern\fR\fR
+.ad
+.RS 17n
+Like \fB-path\fR, but the match is case insensitive.
+.RE
+
+.sp
+.ne 2
+.na
 \fB\fB-iregex\fR \fIpattern\fR\fR
 .ad
 .RS 17n
@@ -528,6 +538,15 @@
 .sp
 .ne 2
 .na
+\fB\fB-path\fR\fR
+.ad
+.RS 17n
+Like \fB-name\fR, but matches the entire file path and not just basename.
+.RE
+
+.sp
+.ne 2
+.na
 \fB\fB-perm\fR [\fB-\fR]\fImode\fR\fR
 .ad
 .RS 17n