Skip to content

Commit

Permalink
3795 find does not support -path or -ipath
Browse files Browse the repository at this point in the history
Reviewed by: Hans Rosenfeld <[email protected]>
Reviewed by: Albert Lee <[email protected]>
Approved by: Dan McDonald <[email protected]>
  • Loading branch information
andy-js authored and Dan McDonald committed Jun 5, 2013
1 parent 9f4ed2b commit 05f3241
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
34 changes: 23 additions & 11 deletions usr/src/cmd/find/find.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/


Expand Down Expand Up @@ -83,10 +84,10 @@ enum Command
{
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
Expand Down Expand Up @@ -125,6 +126,7 @@ static struct Args commands[] =
"-groupacl", F_GROUPACL, Num,
"-iname", INAME, Str,
"-inum", INUM, Num,
"-ipath", IPATH, Str,
"-iregex", IREGEX, Str,
"-links", LINKS, Num,
"-local", LOCAL, Unary,
Expand All @@ -143,6 +145,7 @@ static struct Args commands[] =
"-o", OR, Op,
"-ok", OK, Exec,
"-or", OR, Op,
"-path", PATH, Str,
"-perm", PERM, Num,
"-print", PRINT, Unary,
"-print0", PRINT0, Unary,
Expand Down Expand Up @@ -621,6 +624,8 @@ int *actionp;

case NAME:
case INAME:
case PATH:
case IPATH:
np->first.cp = b;
break;
case REGEX:
Expand Down Expand Up @@ -993,16 +998,20 @@ struct FTW *state;
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));
Expand All @@ -1018,8 +1027,11 @@ struct FTW *state;
#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;
}

Expand Down
19 changes: 19 additions & 0 deletions usr/src/man/man1/find.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -309,6 +310,15 @@ Like \fB-name\fR, but the match is case insensitive.
True if the file has inode number \fIn\fR.
.RE

.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
Expand Down Expand Up @@ -525,6 +535,15 @@ Like \fB-exec\fR, except that the generated command line is printed with a
question mark first, and is executed only if the response is affirmative.
.RE

.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
Expand Down

0 comments on commit 05f3241

Please sign in to comment.