Skip to content

Commit 89b1c4a

Browse files
committed
extmod/vfs: Delegate import_stat to vfs.stat to allow generic FS import.
1 parent 60db809 commit 89b1c4a

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

extmod/vfs.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,26 @@ mp_import_stat_t mp_vfs_import_stat(const char *path) {
130130
return fat_vfs_import_stat(MP_OBJ_TO_PTR(vfs->obj), path_out);
131131
}
132132
#endif
133-
// TODO delegate to vfs.stat() method
134-
return MP_IMPORT_STAT_NO_EXIST;
133+
134+
// delegate to vfs.stat() method
135+
mp_obj_t path_o = mp_obj_new_str(path_out, strlen(path_out));
136+
mp_obj_t stat;
137+
nlr_buf_t nlr;
138+
if (nlr_push(&nlr) == 0) {
139+
stat = mp_vfs_proxy_call(vfs, MP_QSTR_stat, 1, &path_o);
140+
nlr_pop();
141+
} else {
142+
// assume an exception means that the path is not found
143+
return MP_IMPORT_STAT_NO_EXIST;
144+
}
145+
mp_obj_t *items;
146+
mp_obj_get_array_fixed_n(stat, 10, &items);
147+
mp_int_t st_mode = mp_obj_get_int(items[0]);
148+
if (st_mode & MP_S_IFDIR) {
149+
return MP_IMPORT_STAT_DIR;
150+
} else {
151+
return MP_IMPORT_STAT_FILE;
152+
}
135153
}
136154

137155
mp_obj_t mp_vfs_mount(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {

0 commit comments

Comments
 (0)