From 5ae4306418ff7e553b4a2b07f80a7db6e7655037 Mon Sep 17 00:00:00 2001 From: axel Date: Sun, 22 Oct 2006 08:44:29 +1000 Subject: [PATCH] Change meaning of ** to match both files and directories darcs-hash:20061021224429-ac50b-38e46fa533baf9a46d207ab95bfa7af55abbe54a.gz --- wildcard.c | 50 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/wildcard.c b/wildcard.c index 340ba7b32..87f01638d 100644 --- a/wildcard.c +++ b/wildcard.c @@ -478,26 +478,13 @@ int wildcard_expand( const wchar_t *wc, wc_recursive = wcschr( wc, ANY_STRING_RECURSIVE ); is_recursive = ( wc_recursive && (!wc_end || wc_recursive < wc_end)); - /* - This makes sure that the base - directory of the recursive search is - also searched for matching files. - */ - if( is_recursive && (wc_end==(wc+1)) && !(flags & WILDCARD_RECURSIVE ) ) - { - wildcard_expand( wc_end + 1, - base_dir, - flags, - out ); - } - if( flags & ACCEPT_INCOMPLETE ) sb_init( &sb_desc ); /* Is this segment of the wildcard the last? */ - if( !wc_end && !is_recursive ) + if( !wc_end ) { /* Wildcard segment is the last segment, @@ -583,15 +570,38 @@ int wildcard_expand( const wchar_t *wc, if( wildcard_match2( name, wc, 1 ) ) { wchar_t *long_name = make_path( base_dir, name ); + int skip = 0; - al_push_check( out, long_name ); + if( is_recursive ) + { + /* + In recursive mode, we are only + interested in adding files -directories + will be added in the next pass. + */ + struct stat buf; + if( !wstat( long_name, &buf ) ) + { + skip = S_ISDIR(buf.st_mode); + } + } + + if( skip ) + { + free( long_name ); + } + else + { + al_push_check( out, long_name ); + } res = 1; } } } } } - else + + if( wc_end || is_recursive ) { /* Wilcard segment is not the last segment. Recursively call @@ -615,7 +625,13 @@ int wildcard_expand( const wchar_t *wc, */ long ln=MAX_FILE_LENGTH; char * narrow_dir_string = wcs2str( dir_string ); - + + /* + In recursive mode, we look through the direcotry twice. If + so, this rewind is needed. + */ + rewinddir( dir ); + if( narrow_dir_string ) { /*