3232#include "py/mperrno.h"
3333#include "py/obj.h"
3434#include "py/runtime.h"
35+ #include "shared-bindings/os/__init__.h"
3536#include "shared-bindings/storage/__init__.h"
3637
3738STATIC 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
6364 args [0 ] = readonly ? mp_const_true : mp_const_false ;
6465 args [1 ] = mp_const_false ; // Don't make the file system automatically when mounting.
6566
66- // call the underlying object to do any mounting operation
67- mp_vfs_proxy_call (vfs , MP_QSTR_mount , 2 , (mp_obj_t * )& args );
67+ // Check that there's no file or directory with the same name as the mount point.
68+ nlr_buf_t nlr ;
69+ if (nlr_push (& nlr ) == 0 ) {
70+ common_hal_os_stat (mount_path );
71+ nlr_pop ();
72+ // Something with the same name exists.
73+ mp_raise_OSError (MP_EEXIST );
74+ }
6875
6976 // check that the destination mount point is unused
7077 const char * path_out ;
@@ -78,6 +85,9 @@ void common_hal_storage_mount(mp_obj_t vfs_obj, const char* mount_path, bool rea
7885 }
7986 }
8087
88+ // call the underlying object to do any mounting operation
89+ mp_vfs_proxy_call (vfs , MP_QSTR_mount , 2 , (mp_obj_t * )& args );
90+
8191 // Insert the vfs into the mount table by pushing it onto the front of the
8292 // mount table.
8393 mp_vfs_mount_t * * vfsp = & MP_STATE_VM (vfs_mount_table );
0 commit comments