@@ -442,7 +442,7 @@ def _ignore_patterns(path, names):
442442def _copytree (entries , src , dst , symlinks , ignore , copy_function ,
443443 ignore_dangling_symlinks , dirs_exist_ok = False ):
444444 if ignore is not None :
445- ignored_names = ignore (src , set ( os . listdir ( src )) )
445+ ignored_names = ignore (src , { x . name for x in entries } )
446446 else :
447447 ignored_names = set ()
448448
@@ -543,11 +543,12 @@ def copytree(src, dst, symlinks=False, ignore=None, copy_function=copy2,
543543
544544 """
545545 sys .audit ("shutil.copytree" , src , dst )
546- with os .scandir (src ) as entries :
547- return _copytree (entries = entries , src = src , dst = dst , symlinks = symlinks ,
548- ignore = ignore , copy_function = copy_function ,
549- ignore_dangling_symlinks = ignore_dangling_symlinks ,
550- dirs_exist_ok = dirs_exist_ok )
546+ with os .scandir (src ) as itr :
547+ entries = list (itr )
548+ return _copytree (entries = entries , src = src , dst = dst , symlinks = symlinks ,
549+ ignore = ignore , copy_function = copy_function ,
550+ ignore_dangling_symlinks = ignore_dangling_symlinks ,
551+ dirs_exist_ok = dirs_exist_ok )
551552
552553if hasattr (os .stat_result , 'st_file_attributes' ):
553554 # Special handling for directory junctions to make them behave like
0 commit comments