sh: Use dirent.d_type in pathname generation.
authorPeter Avalos <pavalos@dragonflybsd.org>
Sun, 5 Feb 2012 19:20:09 +0000 (11:20 -0800)
committerPeter Avalos <pavalos@dragonflybsd.org>
Sun, 5 Feb 2012 21:03:48 +0000 (13:03 -0800)
This improves performance for globs where a slash or another component
follows a component with metacharacters by eliminating unnecessary
attempts to open directories that are not.

Obtained-from:  FreeBSD 228942
(cherry picked from commit c601174268e0ea6cad93a733cecb3a07b2c503a6)

bin/sh/expand.c

index 2cb3340..c10a0f5 100644 (file)
@@ -36,7 +36,7 @@
  * SUCH DAMAGE.
  *
  * @(#)expand.c        8.5 (Berkeley) 5/15/95
- * $FreeBSD: src/bin/sh/expand.c,v 1.92 2011/12/28 23:30:17 jilles Exp $
+ * $FreeBSD: src/bin/sh/expand.c,v 1.93 2011/12/28 23:40:46 jilles Exp $
  */
 
 #include <sys/types.h>
@@ -1291,6 +1291,10 @@ expmeta(char *enddir, char *name)
                        if (atend)
                                addfname(expdir);
                        else {
+                               if (dp->d_type != DT_UNKNOWN &&
+                                   dp->d_type != DT_DIR &&
+                                   dp->d_type != DT_LNK)
+                                       continue;
                                if (enddir + namlen + 2 > expdir_end)
                                        continue;
                                enddir[namlen] = '/';