diff options
author | Damien George <damien.p.george@gmail.com> | 2016-12-02 15:13:29 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-12-02 15:13:29 +1100 |
commit | f7545b200ef95632f91a9fe76394d5c19a87b280 (patch) | |
tree | a0beec3b7db0c5ee9cdf1157bf9c289f7b2f7c3c | |
parent | b7df3e541a49a1cb72862c4015b6a883a63e1e29 (diff) | |
download | micropython-f7545b200ef95632f91a9fe76394d5c19a87b280.tar.gz micropython-f7545b200ef95632f91a9fe76394d5c19a87b280.zip |
stmhal/moduos: Implement POSIX behaviour of rename, allow to overwrite.
-rw-r--r-- | stmhal/moduos.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/stmhal/moduos.c b/stmhal/moduos.c index 3fbdcbe22d..b3c6570a5b 100644 --- a/stmhal/moduos.c +++ b/stmhal/moduos.c @@ -183,6 +183,14 @@ STATIC mp_obj_t os_rename(mp_obj_t path_in, mp_obj_t path_out) { const char *old_path = mp_obj_str_get_str(path_in); const char *new_path = mp_obj_str_get_str(path_out); FRESULT res = f_rename(old_path, new_path); + if (res == FR_EXIST) { + // if new_path exists then try removing it + res = f_unlink(new_path); + if (res == FR_OK) { + // try to rename again + res = f_rename(old_path, new_path); + } + } switch (res) { case FR_OK: return mp_const_none; |