@@ -44,7 +44,7 @@ STATIC mp_vfs_mount_t *lookup_path(const char* path, mp_obj_t *path_out) {
44
44
const char * p_out ;
45
45
mp_vfs_mount_t * vfs = mp_vfs_lookup_path (path , & p_out );
46
46
if (vfs != MP_VFS_NONE && vfs != MP_VFS_ROOT ) {
47
- * path_out = mp_obj_new_str_of_type (mp_obj_get_type ( path ) ,
47
+ * path_out = mp_obj_new_str_of_type (& mp_type_str ,
48
48
(const byte * )p_out , strlen (p_out ));
49
49
}
50
50
return vfs ;
@@ -95,18 +95,28 @@ mp_obj_t common_hal_os_listdir(const char* path) {
95
95
mp_obj_t path_out ;
96
96
mp_vfs_mount_t * vfs = lookup_path (path , & path_out );
97
97
98
+ mp_vfs_ilistdir_it_t iter ;
99
+ mp_obj_t iter_obj = MP_OBJ_FROM_PTR (& iter );
100
+
98
101
if (vfs == MP_VFS_ROOT ) {
99
102
// list the root directory
100
- mp_vfs_ilistdir_it_t * iter = m_new_obj ( mp_vfs_ilistdir_it_t ) ;
101
- iter -> base . type = & mp_type_polymorph_iter ;
102
- iter -> iternext = mp_vfs_ilistdir_it_iternext ;
103
- iter -> cur . vfs = MP_STATE_VM ( vfs_mount_table ) ;
104
- iter -> is_str = mp_obj_get_type ( path ) == & mp_type_str ;
105
- iter -> is_iter = false;
106
- return MP_OBJ_FROM_PTR ( iter );
103
+ iter . base . type = & mp_type_polymorph_iter ;
104
+ iter . iternext = mp_vfs_ilistdir_it_iternext ;
105
+ iter . cur . vfs = MP_STATE_VM ( vfs_mount_table ) ;
106
+ iter . is_str = mp_obj_get_type ( path ) == & mp_type_str ;
107
+ iter . is_iter = false ;
108
+ } else {
109
+ iter_obj = mp_vfs_proxy_call ( vfs , MP_QSTR_ilistdir , 1 , & path_out );
107
110
}
108
111
109
- return mp_vfs_proxy_call (vfs , MP_QSTR_ilistdir , 1 , & path_out );
112
+ mp_obj_t dir_list = mp_obj_new_list (0 , NULL );
113
+ mp_obj_t next ;
114
+ while ((next = mp_iternext (iter_obj )) != MP_OBJ_STOP_ITERATION ) {
115
+ mp_obj_t * items ;
116
+ mp_obj_get_array_fixed_n (next , 3 , & items );
117
+ mp_obj_list_append (dir_list , items [0 ]);
118
+ }
119
+ return dir_list ;
110
120
}
111
121
112
122
void common_hal_os_mkdir (const char * path ) {
0 commit comments