@@ -446,16 +446,13 @@ def _scandir(self, path, namespaces=None):
446446 self .check ()
447447 namespaces = namespaces or ()
448448 sys_path = self ._get_validated_syspath (path )
449+ sys_path_u = fsdecode (sys_path )
449450 with convert_os_errors ('scandir' , path , directory = True ):
450451 for dir_entry in scandir (sys_path ):
451- entry_name_u = fsdecode (dir_entry .name )
452- entry_name_b = fsencode (entry_name_u )
453- entry_path_b = os .path .join (sys_path , entry_name_b )
454- entry_path_u = fsdecode (entry_path_b )
455-
452+ entry_name = fsdecode (dir_entry .name )
456453 info = {
457454 "basic" : {
458- "name" : entry_name_u ,
455+ "name" : entry_name ,
459456 "is_dir" : dir_entry .is_dir ()
460457 }
461458 }
@@ -476,7 +473,8 @@ def _scandir(self, path, namespaces=None):
476473 for k in dir (lstat_result ) if k .startswith ('st_' )
477474 }
478475 if 'link' in namespaces :
479- info ['link' ] = self ._make_link_info (entry_path_u )
476+ entry_path = os .path .join (sys_path_u , entry_name )
477+ info ['link' ] = self ._make_link_info (entry_path )
480478 if 'access' in namespaces :
481479 stat_result = dir_entry .stat ()
482480 info ['access' ] = \
@@ -490,17 +488,17 @@ def _scandir(self, path, namespaces=None):
490488 self .check ()
491489 namespaces = namespaces or ()
492490 sys_path = self ._get_validated_syspath (path )
491+ sys_path_u = fsdecode (sys_path )
493492 with convert_os_errors ('scandir' , path , directory = True ):
494493 for entry_name in os .listdir (sys_path ):
495- entry_name_u = fsdecode (entry_name )
496- entry_name_b = fsencode (entry_name )
497- entry_path_b = os .path .join (sys_path , entry_name_b )
498- entry_path_u = fsdecode (entry_path_b )
494+ entry_name = fsdecode (entry_name )
495+ entry_path = os .path .join (sys_path_u , entry_name )
496+ entry_path_b = fsdecode (entry_path )
499497 stat_result = os .stat (entry_path_b )
500498
501499 info = {
502500 "basic" : {
503- "name" : entry_name_u ,
501+ "name" : entry_name ,
504502 "is_dir" : stat .S_ISDIR (stat_result .st_mode ),
505503 }
506504 }
@@ -519,7 +517,7 @@ def _scandir(self, path, namespaces=None):
519517 for k in dir (lstat_result ) if k .startswith ('st_' )
520518 }
521519 if 'link' in namespaces :
522- info ['link' ] = self ._make_link_info (entry_path_u )
520+ info ['link' ] = self ._make_link_info (entry_path )
523521 if 'access' in namespaces :
524522 info ['access' ] = \
525523 self ._make_access_from_stat (stat_result )
0 commit comments