[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: es bug



I wrote:
> On 21 September 1994, Tom Tromey wrote
> > I've noticed that "*/" expands to all file names with "/" appended,
> > instead of just the names of directories.  I think this is a bug --
> > all the other glob code I've used does the right thing (expands to
> > just directories).
> I looked at it a little, and I think that listglob() probably needs to
> do somethng different when slashcount > 0, but I haven't really thought
> it through.

I think I found a better way of handling this, by moving the
is-a-directory? check earlier in dirmatch().  Here's a patch, but I
don't guarantee that it doesn't break other things.  es with this does
pass the trip and a few sanity tests I tried, so I'll start running it
and let the list know if I hit any problems.

Paul

*** glob.c	Tue Nov 29 20:04:04 1994
--- ../es-0.84/glob.c	Thu Apr 29 22:09:08 1993
***************
*** 50,63 ****
  	static Dirent *dp;
  	static struct stat s;
  
- 	/*
- 	 * opendir succeeds on regular files on some systems, so the stat call
- 	 * is necessary (sigh);  the check is done here instead of with the
- 	 * opendir to handle a trailing slash.
- 	 */
- 	if (stat(dirname, &s) == -1 || (s.st_mode & S_IFMT) != S_IFDIR)
- 		return NULL;	
- 
  	if (!haswild(pattern, quote)) {
  		char *name = str("%s%s", prefix, pattern);
  		if (lstat(name, &s) == -1)
--- 50,55 ----
***************
*** 67,74 ****
  
  	assert(gcisblocked());
  
! 	dirp = opendir(dirname);
! 	if (dirp == NULL)
  		return NULL;	
  	for (list = NULL, prevp = &list; (dp = readdir(dirp)) != NULL;)
  		if (match(dp->d_name, pattern, quote) && (!ishiddenfile(dp->d_name) || *pattern == '.')) {
--- 59,66 ----
  
  	assert(gcisblocked());
  
! 	/* opendir succeeds on regular files on some systems, so the stat() call is necessary (sigh) */
! 	if (stat(dirname, &s) == -1 || (s.st_mode & S_IFMT) != S_IFDIR || (dirp = opendir(dirname)) == NULL)
  		return NULL;	
  	for (list = NULL, prevp = &list; (dp = readdir(dirp)) != NULL;)
  		if (match(dp->d_name, pattern, quote) && (!ishiddenfile(dp->d_name) || *pattern == '.')) {