Print this page
3795 find does not support -path or -ipath

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/find/find.c
          +++ new/usr/src/cmd/find/find.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
  23   23   * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
       24 + * Copyright (c) 2013 Andrew Stormont.  All rights reserved.
  24   25   */
  25   26  
  26   27  
  27   28  /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
  28   29  /*        All Rights Reserved   */
  29   30  
  30   31  
  31   32  /*      Parts of this product may be derived from               */
  32   33  /*      Mortice Kern Systems Inc. and Berkeley 4.3 BSD systems. */
  33   34  /*      licensed from  Mortice Kern Systems Inc. and            */
↓ open down ↓ 42 lines elided ↑ open up ↑
  76   77  /*
  77   78   * This is the list of operations
  78   79   * F_USER and F_GROUP are named to avoid conflict with USER and GROUP defined
  79   80   * in sys/acl.h
  80   81   */
  81   82  
  82   83  enum Command
  83   84  {
  84   85          PRINT,
  85   86          ACL, AMIN, AND, ATIME, CMIN, CPIO, CSIZE, CTIME, DEPTH, EXEC, F_GROUP,
  86      -        F_GROUPACL, F_USER, F_USERACL, FOLLOW, FSTYPE, INAME, INUM, IREGEX,
  87      -        LINKS, LOCAL, LPAREN, LS, MAXDEPTH, MINDEPTH, MMIN, MOUNT, MTIME, NAME,
  88      -        NCPIO, NEWER, NOGRP, NOT, NOUSER, OK, OR, PERM, PRINT0, PRUNE, REGEX,
  89      -        RPAREN, SIZE, TYPE, VARARGS, XATTR
       87 +        F_GROUPACL, F_USER, F_USERACL, FOLLOW, FSTYPE, INAME, INUM, IPATH,
       88 +        IREGEX, LINKS, LOCAL, LPAREN, LS, MAXDEPTH, MINDEPTH, MMIN, MOUNT,
       89 +        MTIME, NAME, NCPIO, NEWER, NOGRP, NOT, NOUSER, OK, OR, PATH, PERM,
       90 +        PRINT0, PRUNE, REGEX, RPAREN, SIZE, TYPE, VARARGS, XATTR
  90   91  };
  91   92  
  92   93  enum Type
  93   94  {
  94   95          Unary, Id, Num, Str, Exec, Cpio, Op
  95   96  };
  96   97  
  97   98  struct Args
  98   99  {
  99  100          char            name[10];
↓ open down ↓ 18 lines elided ↑ open up ↑
 118  119          "-cpio",        CPIO,           Cpio,
 119  120          "-ctime",       CTIME,          Num,
 120  121          "-depth",       DEPTH,          Unary,
 121  122          "-exec",        EXEC,           Exec,
 122  123          "-follow",      FOLLOW,         Unary,
 123  124          "-fstype",      FSTYPE,         Str,
 124  125          "-group",       F_GROUP,        Num,
 125  126          "-groupacl",    F_GROUPACL,     Num,
 126  127          "-iname",       INAME,          Str,
 127  128          "-inum",        INUM,           Num,
      129 +        "-ipath",       IPATH,          Str,
 128  130          "-iregex",      IREGEX,         Str,
 129  131          "-links",       LINKS,          Num,
 130  132          "-local",       LOCAL,          Unary,
 131  133          "-ls",          LS,             Unary,
 132  134          "-maxdepth",    MAXDEPTH,       Num,
 133  135          "-mindepth",    MINDEPTH,       Num,
 134  136          "-mmin",        MMIN,           Num,
 135  137          "-mount",       MOUNT,          Unary,
 136  138          "-mtime",       MTIME,          Num,
 137  139          "-name",        NAME,           Str,
 138  140          "-ncpio",       NCPIO,          Cpio,
 139  141          "-newer",       NEWER,          Str,
 140  142          "-nogroup",     NOGRP,          Unary,
 141  143          "-not",         NOT,            Op,
 142  144          "-nouser",      NOUSER,         Unary,
 143  145          "-o",           OR,             Op,
 144  146          "-ok",          OK,             Exec,
 145  147          "-or",          OR,             Op,
      148 +        "-path",        PATH,           Str,
 146  149          "-perm",        PERM,           Num,
 147  150          "-print",       PRINT,          Unary,
 148  151          "-print0",      PRINT0,         Unary,
 149  152          "-prune",       PRUNE,          Unary,
 150  153          "-regex",       REGEX,          Str,
 151  154          "-size",        SIZE,           Num,
 152  155          "-type",        TYPE,           Num,
 153  156          "-user",        F_USER,         Num,
 154  157          "-useracl",     F_USERACL,      Num,
 155  158          "-xattr",       XATTR,          Unary,
↓ open down ↓ 458 lines elided ↑ open up ↑
 614  617                                          np->first.vp = varargs(np->first.ap);
 615  618                                          np->action = VARARGS;
 616  619                                          break;
 617  620                                  }
 618  621                                  av++;
 619  622                          }
 620  623                          break;
 621  624  
 622  625                  case NAME:
 623  626                  case INAME:
      627 +                case PATH:
      628 +                case IPATH:
 624  629                          np->first.cp = b;
 625  630                          break;
 626  631                  case REGEX:
 627  632                  case IREGEX: {
 628  633                          int error;
 629  634                          size_t errlen;
 630  635                          char *errmsg;
 631  636  
 632  637                          if ((preg = realloc(preg, (npreg + 1) *
 633  638                              sizeof (regex_t))) == NULL)
↓ open down ↓ 352 lines elided ↑ open up ↑
 986  991                          break;
 987  992                  }
 988  993  
 989  994                  case DEPTH:
 990  995                  case MOUNT:
 991  996                  case FOLLOW:
 992  997                          val = 1;
 993  998                          break;
 994  999  
 995 1000                  case NAME:
 996      -                case INAME: {
 997      -                        char *name1;
 998      -                        int fnmflags = (np->action == INAME) ?
 999      -                            FNM_IGNORECASE : 0;
     1001 +                case INAME:
     1002 +                case PATH:
     1003 +                case IPATH: {
     1004 +                        char *path;
     1005 +                        int fnmflags = 0;
     1006 +
     1007 +                        if (np->action == INAME || np->action == IPATH)
     1008 +                                fnmflags = FNM_IGNORECASE;
1000 1009  
1001 1010                          /*
1002 1011                           * basename(3c) may modify name, so
1003 1012                           * we need to pass another string
1004 1013                           */
1005      -                        if ((name1 = strdup(name)) == NULL) {
     1014 +                        if ((path = strdup(name)) == NULL) {
1006 1015                                  (void) fprintf(stderr,
1007 1016                                      gettext("%s: cannot strdup() %s: %s\n"),
1008 1017                                      cmdname, name, strerror(errno));
1009 1018                                  exit(2);
1010 1019                          }
1011 1020                          /*
1012 1021                           * XPG4 find should not treat a leading '.' in a
1013 1022                           * filename specially for pattern matching.
1014 1023                           * /usr/bin/find  will not pattern match a leading
1015 1024                           * '.' in a filename, unless '.' is explicitly
1016 1025                           * specified.
1017 1026                           */
1018 1027  #ifndef XPG4
1019 1028                          fnmflags |= FNM_PERIOD;
1020 1029  #endif
1021      -                        val = !fnmatch(np->first.cp, basename(name1), fnmflags);
1022      -                        free(name1);
     1030 +
     1031 +                        val = !fnmatch(np->first.cp,
     1032 +                            (np->action == NAME || np->action == INAME)
     1033 +                                ? basename(path) : path, fnmflags);
     1034 +                        free(path);
1023 1035                          break;
1024 1036                  }
1025 1037  
1026 1038                  case PRUNE:
1027 1039                          if (type == FTW_D)
1028 1040                                  state->quit = FTW_PRUNE;
1029 1041                          val = 1;
1030 1042                          break;
1031 1043                  case NOUSER:
1032 1044                          val = ((getpwuid(statb->st_uid)) == 0);
↓ open down ↓ 1184 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX