Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 11 Jan 2014 21:12:27 +0000 (UTC)
From:      Jilles Tjoelker <jilles@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r260555 - head/usr.bin/find
Message-ID:  <201401112112.s0BLCRJL050699@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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':



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201401112112.s0BLCRJL050699>