aboutsummaryrefslogtreecommitdiff
path: root/extmod/vfs.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-05-02 17:08:48 +1000
committerDamien George <damien.p.george@gmail.com>2018-05-02 17:08:48 +1000
commit89b1c4a60cd43697e755b645127387d3b34e6d3f (patch)
treeb7bbba83f70e1abdf35b7cde47691e47a7ce15d1 /extmod/vfs.c
parent60db80920a1eac962e43991fcffafd16edd11885 (diff)
extmod/vfs: Delegate import_stat to vfs.stat to allow generic FS import.
Diffstat (limited to 'extmod/vfs.c')
-rw-r--r--extmod/vfs.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/extmod/vfs.c b/extmod/vfs.c
index 0585de1c7..16f75aba9 100644
--- a/extmod/vfs.c
+++ b/extmod/vfs.c
@@ -130,8 +130,26 @@ mp_import_stat_t mp_vfs_import_stat(const char *path) {
return fat_vfs_import_stat(MP_OBJ_TO_PTR(vfs->obj), path_out);
}
#endif
- // TODO delegate to vfs.stat() method
- return MP_IMPORT_STAT_NO_EXIST;
+
+ // delegate to vfs.stat() method
+ mp_obj_t path_o = mp_obj_new_str(path_out, strlen(path_out));
+ mp_obj_t stat;
+ nlr_buf_t nlr;
+ if (nlr_push(&nlr) == 0) {
+ stat = mp_vfs_proxy_call(vfs, MP_QSTR_stat, 1, &path_o);
+ nlr_pop();
+ } else {
+ // assume an exception means that the path is not found
+ return MP_IMPORT_STAT_NO_EXIST;
+ }
+ mp_obj_t *items;
+ mp_obj_get_array_fixed_n(stat, 10, &items);
+ mp_int_t st_mode = mp_obj_get_int(items[0]);
+ if (st_mode & MP_S_IFDIR) {
+ return MP_IMPORT_STAT_DIR;
+ } else {
+ return MP_IMPORT_STAT_FILE;
+ }
}
mp_obj_t mp_vfs_mount(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {