@@ -332,6 +332,7 @@ def select_wildcard(path, dir_fd=None, rel_path=None, exists=False, empty=False)
332
332
continue
333
333
except OSError :
334
334
continue
335
+ # Add trailing slash.
335
336
entry_path = self .concat_path (entry_path , self .sep )
336
337
if fd is not None :
337
338
entry_name = entry_name + self .sep
@@ -408,29 +409,27 @@ def select_recursive_step(stack, match_pos):
408
409
pass
409
410
else :
410
411
for entry , entry_name , entry_path in entries :
411
- is_dir = False
412
412
try :
413
413
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
415
421
except OSError :
416
- pass
422
+ if dir_only :
423
+ continue
417
424
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 ):
420
426
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
434
433
435
434
return select_recursive
436
435
@@ -480,7 +479,6 @@ def scandir(path):
480
479
481
480
@staticmethod
482
481
def scandir_fd (fd , prefix ):
483
- prefix = os .path .join (prefix , prefix [:0 ])
484
482
with os .scandir (fd ) as scandir_it :
485
483
entries = list (scandir_it )
486
484
return ((entry , entry .name , prefix + entry .name ) for entry in entries )
0 commit comments