32
32
#include "py/mperrno.h"
33
33
#include "py/obj.h"
34
34
#include "py/runtime.h"
35
+ #include "shared-bindings/os/__init__.h"
35
36
#include "shared-bindings/storage/__init__.h"
36
37
37
38
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
63
64
args [0 ] = readonly ? mp_const_true : mp_const_false ;
64
65
args [1 ] = mp_const_false ; // Don't make the file system automatically when mounting.
65
66
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
+ }
68
75
69
76
// check that the destination mount point is unused
70
77
const char * path_out ;
@@ -78,6 +85,9 @@ void common_hal_storage_mount(mp_obj_t vfs_obj, const char* mount_path, bool rea
78
85
}
79
86
}
80
87
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
+
81
91
// Insert the vfs into the mount table by pushing it onto the front of the
82
92
// mount table.
83
93
mp_vfs_mount_t * * vfsp = & MP_STATE_VM (vfs_mount_table );
0 commit comments