1 parent b7df3e5 commit f7545b2Copy full SHA for f7545b2
1 file changed
stmhal/moduos.c
@@ -183,6 +183,14 @@ STATIC mp_obj_t os_rename(mp_obj_t path_in, mp_obj_t path_out) {
183
const char *old_path = mp_obj_str_get_str(path_in);
184
const char *new_path = mp_obj_str_get_str(path_out);
185
FRESULT res = f_rename(old_path, new_path);
186
+ if (res == FR_EXIST) {
187
+ // if new_path exists then try removing it
188
+ res = f_unlink(new_path);
189
+ if (res == FR_OK) {
190
+ // try to rename again
191
+ res = f_rename(old_path, new_path);
192
+ }
193
194
switch (res) {
195
case FR_OK:
196
return mp_const_none;
0 commit comments