@@ -332,6 +332,7 @@ def select_wildcard(path, dir_fd=None, rel_path=None, exists=False, empty=False)
332332 continue
333333 except OSError :
334334 continue
335+ # Add trailing slash.
335336 entry_path = self .concat_path (entry_path , self .sep )
336337 if fd is not None :
337338 entry_name = entry_name + self .sep
@@ -408,29 +409,27 @@ def select_recursive_step(stack, match_pos):
408409 pass
409410 else :
410411 for entry , entry_name , entry_path in entries :
411- is_dir = False
412412 try :
413413 if entry .is_dir (follow_symlinks = follow_symlinks ):
414- is_dir = True
414+ # Add trailing slash.
415+ dir_path = self .concat_path (entry_path , self .sep )
416+ if fd is not None :
417+ entry_name = entry_name + self .sep
418+ stack .append ((dir_path , fd , entry_name ))
419+ elif dir_only :
420+ continue
415421 except OSError :
416- pass
422+ if dir_only :
423+ continue
417424
418- if is_dir or not dir_only :
419- entry_path_str = str (entry_path )
425+ if match is None or match (str (entry_path ), match_pos ):
420426 if dir_only :
421- entry_path = self .concat_path (entry_path , self .sep )
422- if fd is not None :
423- entry_name = entry_name + self .sep
424- if match is None or match (entry_path_str , match_pos ):
425- if dir_only :
426- yield from select_next (
427- entry_path , fd , entry_name , exists = True )
428- else :
429- # Optimization: directly yield the path if this is
430- # last pattern part.
431- yield entry_path
432- if is_dir :
433- stack .append ((entry_path , fd , entry_name ))
427+ yield from select_next (
428+ dir_path , fd , entry_name , exists = True )
429+ else :
430+ # Optimization: directly yield the path if this is
431+ # last pattern part.
432+ yield entry_path
434433
435434 return select_recursive
436435
@@ -480,7 +479,6 @@ def scandir(path):
480479
481480 @staticmethod
482481 def scandir_fd (fd , prefix ):
483- prefix = os .path .join (prefix , prefix [:0 ])
484482 with os .scandir (fd ) as scandir_it :
485483 entries = list (scandir_it )
486484 return ((entry , entry .name , prefix + entry .name ) for entry in entries )
0 commit comments