From 0911531aab93ef035a7b03c73875a994e22c726e Mon Sep 17 00:00:00 2001 From: Chet Ramey Date: Fri, 22 May 2009 12:35:55 -0400 Subject: [PATCH] Patch-ID: bash40-025 Bug-Reported-by: Matt Zyzik Bug-Reference-ID: <20090519011418.GA21431@ice.filescope.com> Bug-Reference-URL: http://lists.gnu.org/archive/html/bug-bash/2009-05/msg00044.html Bug-Description: bash40-024 introduced a regression for constructs like **/*.cs; that expansion would no longer include matching files in the current directory. This patch undoes portions of bash40-024 and fixes the original problem in a different way. This patch, in file bash40-025, was downloaded from ftp.gnu.org on 2011-05-29, and bash40-025.sig was furthermore verified, yielding the following output: gpg: Signature made Wed 22 Jul 2009 08:39:02 AM EDT using DSA key ID 64EA74AB gpg: Good signature from "Chet Ramey " --- lib/glob/glob.c | 27 ++++++++++++++++++++++----- patchlevel.h | 2 +- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/glob/glob.c b/lib/glob/glob.c index 7b2cf7f..cc95194 100644 --- a/lib/glob/glob.c +++ b/lib/glob/glob.c @@ -665,9 +665,10 @@ glob_vector (pat, dir, flags) (void) closedir (d); } - /* compat: if GX_ALLDIRS, add the passed directory also, but don't add an - empty directory name. */ - if (add_current && (flags & GX_NULLDIR) == 0) + /* compat: if GX_ADDCURDIR, add the passed directory also. Add an empty + directory name as a placeholder if GX_NULLDIR (in which case the passed + directory name is "."). */ + if (add_current) { sdlen = strlen (dir); nextname = (char *)malloc (sdlen + 1); @@ -679,7 +680,10 @@ glob_vector (pat, dir, flags) nextlink->name = nextname; nextlink->next = lastlink; lastlink = nextlink; - bcopy (dir, nextname, sdlen + 1); + if (flags & GX_NULLDIR) + nextname[0] = '\0'; + else + bcopy (dir, nextname, sdlen + 1); ++count; } } @@ -1007,11 +1011,24 @@ glob_filename (pathname, flags) /* Just return what glob_vector () returns appended to the directory name. */ + /* If flags & GX_ALLDIRS, we're called recursively */ dflags = flags & ~GX_MARKDIRS; if (directory_len == 0) dflags |= GX_NULLDIR; if ((flags & GX_GLOBSTAR) && filename[0] == '*' && filename[1] == '*' && filename[2] == '\0') - dflags |= GX_ALLDIRS|GX_ADDCURDIR; + { + dflags |= GX_ALLDIRS|GX_ADDCURDIR; +#if 0 + /* If we want all directories (dflags & GX_ALLDIRS) and we're not + being called recursively as something like `echo **/*.o' + ((flags & GX_ALLDIRS) == 0), we want to prevent glob_vector from + adding a null directory name to the front of the temp_results + array. We turn off ADDCURDIR if not called recursively and + dlen == 0 */ +#endif + if (directory_len == 0 && (flags & GX_ALLDIRS) == 0) + dflags &= ~GX_ADDCURDIR; + } temp_results = glob_vector (filename, (directory_len == 0 ? "." : directory_name), dflags); diff --git a/patchlevel.h b/patchlevel.h index fb0be51..cc3503a 100644 --- a/patchlevel.h +++ b/patchlevel.h @@ -25,6 +25,6 @@ regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh looks for to find the patch level (for the sccs version string). */ -#define PATCHLEVEL 24 +#define PATCHLEVEL 25 #endif /* _PATCHLEVEL_H_ */ -- 2.11.4.GIT