summaryrefslogtreecommitdiff
path: root/shared-module
diff options
context:
space:
mode:
authorhathach <thach@tinyusb.org>2018-06-19 14:50:17 +0700
committerhathach <thach@tinyusb.org>2018-06-19 14:50:17 +0700
commit6d2702ed98edfc66e998280582cafea5e4736e8c (patch)
tree3df557af79aba4f87880dec15d20cdad3656d4f2 /shared-module
parent9fc0ec6af8e63d62843b281a14f7f8c5b330e58f (diff)
parent4e7eee3553665116e625891d01f9ea89c527a24a (diff)
Merge branch 'master' into nrf52840_usbboot
Diffstat (limited to 'shared-module')
-rw-r--r--shared-module/os/__init__.c2
-rw-r--r--shared-module/storage/__init__.c14
2 files changed, 13 insertions, 3 deletions
diff --git a/shared-module/os/__init__.c b/shared-module/os/__init__.c
index 9eb04e281..1dadd254a 100644
--- a/shared-module/os/__init__.c
+++ b/shared-module/os/__init__.c
@@ -103,7 +103,7 @@ mp_obj_t common_hal_os_listdir(const char* path) {
iter.base.type = &mp_type_polymorph_iter;
iter.iternext = mp_vfs_ilistdir_it_iternext;
iter.cur.vfs = MP_STATE_VM(vfs_mount_table);
- iter.is_str = mp_obj_get_type(path) == &mp_type_str;
+ iter.is_str = true;
iter.is_iter = false;
} else {
iter_obj = mp_vfs_proxy_call(vfs, MP_QSTR_ilistdir, 1, &path_out);
diff --git a/shared-module/storage/__init__.c b/shared-module/storage/__init__.c
index 5b0bbe01e..cc10ebd5a 100644
--- a/shared-module/storage/__init__.c
+++ b/shared-module/storage/__init__.c
@@ -32,6 +32,7 @@
#include "py/mperrno.h"
#include "py/obj.h"
#include "py/runtime.h"
+#include "shared-bindings/os/__init__.h"
#include "shared-bindings/storage/__init__.h"
STATIC mp_obj_t mp_vfs_proxy_call(mp_vfs_mount_t *vfs, qstr meth_name, size_t n_args, const mp_obj_t *args) {
@@ -63,8 +64,14 @@ void common_hal_storage_mount(mp_obj_t vfs_obj, const char* mount_path, bool rea
args[0] = readonly ? mp_const_true : mp_const_false;
args[1] = mp_const_false; // Don't make the file system automatically when mounting.
- // call the underlying object to do any mounting operation
- mp_vfs_proxy_call(vfs, MP_QSTR_mount, 2, (mp_obj_t*)&args);
+ // Check that there's no file or directory with the same name as the mount point.
+ nlr_buf_t nlr;
+ if (nlr_push(&nlr) == 0) {
+ common_hal_os_stat(mount_path);
+ nlr_pop();
+ // Something with the same name exists.
+ mp_raise_OSError(MP_EEXIST);
+ }
// check that the destination mount point is unused
const char *path_out;
@@ -78,6 +85,9 @@ void common_hal_storage_mount(mp_obj_t vfs_obj, const char* mount_path, bool rea
}
}
+ // call the underlying object to do any mounting operation
+ mp_vfs_proxy_call(vfs, MP_QSTR_mount, 2, (mp_obj_t*)&args);
+
// Insert the vfs into the mount table by pushing it onto the front of the
// mount table.
mp_vfs_mount_t **vfsp = &MP_STATE_VM(vfs_mount_table);