@@ -454,12 +454,15 @@ def __init__(self, name, child_parts):
454454 _Selector .__init__ (self , child_parts )
455455
456456 def _select_from (self , parent_path , is_dir , exists , listdir ):
457- if not is_dir (parent_path ):
457+ try :
458+ if not is_dir (parent_path ):
459+ return
460+ path = parent_path ._make_child_relpath (self .name )
461+ if exists (path ):
462+ for p in self .successor ._select_from (path , is_dir , exists , listdir ):
463+ yield p
464+ except PermissionError :
458465 return
459- path = parent_path ._make_child_relpath (self .name )
460- if exists (path ):
461- for p in self .successor ._select_from (path , is_dir , exists , listdir ):
462- yield p
463466
464467
465468class _WildcardSelector (_Selector ):
@@ -469,15 +472,19 @@ def __init__(self, pat, child_parts):
469472 _Selector .__init__ (self , child_parts )
470473
471474 def _select_from (self , parent_path , is_dir , exists , listdir ):
472- if not is_dir (parent_path ):
475+ try :
476+ if not is_dir (parent_path ):
477+ return
478+ cf = parent_path ._flavour .casefold
479+ for name in listdir (parent_path ):
480+ casefolded = cf (name )
481+ if self .pat .match (casefolded ):
482+ path = parent_path ._make_child_relpath (name )
483+ for p in self .successor ._select_from (path , is_dir , exists , listdir ):
484+ yield p
485+ except PermissionError :
473486 return
474- cf = parent_path ._flavour .casefold
475- for name in listdir (parent_path ):
476- casefolded = cf (name )
477- if self .pat .match (casefolded ):
478- path = parent_path ._make_child_relpath (name )
479- for p in self .successor ._select_from (path , is_dir , exists , listdir ):
480- yield p
487+
481488
482489
483490class _RecursiveWildcardSelector (_Selector ):
@@ -494,19 +501,22 @@ def _iterate_directories(self, parent_path, is_dir, listdir):
494501 yield p
495502
496503 def _select_from (self , parent_path , is_dir , exists , listdir ):
497- if not is_dir (parent_path ):
504+ try :
505+ if not is_dir (parent_path ):
506+ return
507+ with _cached (listdir ) as listdir :
508+ yielded = set ()
509+ try :
510+ successor_select = self .successor ._select_from
511+ for starting_point in self ._iterate_directories (parent_path , is_dir , listdir ):
512+ for p in successor_select (starting_point , is_dir , exists , listdir ):
513+ if p not in yielded :
514+ yield p
515+ yielded .add (p )
516+ finally :
517+ yielded .clear ()
518+ except PermissionError :
498519 return
499- with _cached (listdir ) as listdir :
500- yielded = set ()
501- try :
502- successor_select = self .successor ._select_from
503- for starting_point in self ._iterate_directories (parent_path , is_dir , listdir ):
504- for p in successor_select (starting_point , is_dir , exists , listdir ):
505- if p not in yielded :
506- yield p
507- yielded .add (p )
508- finally :
509- yielded .clear ()
510520
511521
512522#
0 commit comments