Author: jilles
Date: Sat Jan 11 21:12:27 2014
New Revision: 260555
URL: http://svnweb.freebsd.org/changeset/base/260555

Log:
  find: Allow -type d without statting everything.
  
  fts(3) detects directories even in FTS_NOSTAT mode (so it can descend into
  them).
  
  No functional change is intended, but find commands that use -type d but no
  primaries that still require stat/lstat calls make considerably fewer system
  calls.

Modified:
  head/usr.bin/find/function.c

Modified: head/usr.bin/find/function.c
==============================================================================
--- head/usr.bin/find/function.c        Sat Jan 11 20:49:22 2014        
(r260554)
+++ head/usr.bin/find/function.c        Sat Jan 11 21:12:27 2014        
(r260555)
@@ -1552,7 +1552,12 @@ c_sparse(OPTION *option, char ***argvp _
 int
 f_type(PLAN *plan, FTSENT *entry)
 {
-       return (entry->fts_statp->st_mode & S_IFMT) == plan->m_data;
+       if (plan->m_data == S_IFDIR)
+               return (entry->fts_info == FTS_D || entry->fts_info == FTS_DC ||
+                   entry->fts_info == FTS_DNR || entry->fts_info == FTS_DOT ||
+                   entry->fts_info == FTS_DP);
+       else
+               return (entry->fts_statp->st_mode & S_IFMT) == plan->m_data;
 }
 
 PLAN *
@@ -1563,7 +1568,8 @@ c_type(OPTION *option, char ***argvp)
        mode_t  mask;
 
        typestring = nextarg(option, argvp);
-       ftsoptions &= ~FTS_NOSTAT;
+       if (typestring[0] != 'd')
+               ftsoptions &= ~FTS_NOSTAT;
 
        switch (typestring[0]) {
        case 'b':
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to