summaryrefslogtreecommitdiffstatshomepage
path: root/esp8266
diff options
context:
space:
mode:
authorRobert HH <robert@hammelrath.com>2016-05-16 10:17:11 +0200
committerRobert HH <robert@hammelrath.com>2016-05-16 13:19:13 +0200
commita676a41cb7f50d0aab4230be19e9b2bb508f754e (patch)
treea6d91ac350489c4692e9967e9e91718607fa262d /esp8266
parentafce978aca77805e84a2442c93c26dab045784f8 (diff)
downloadmicropython-a676a41cb7f50d0aab4230be19e9b2bb508f754e.tar.gz
micropython-a676a41cb7f50d0aab4230be19e9b2bb508f754e.zip
esp8266/moduos.c: Addition of the rename method to module uos.
That one was missing in the module, even if it was available in the vfs object. The change consist of adding the name and preparing the call to the underlying vfs module, similar to what was already implemented e.g. for remove. Rename is useful by itself, or for instance for a safe file replace, consisting of the sequence: write to a temp file delete the original file rename the temp file to the original file's name
Diffstat (limited to 'esp8266')
-rw-r--r--esp8266/moduos.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/esp8266/moduos.c b/esp8266/moduos.c
index bc2838d2d4..deac0c960b 100644
--- a/esp8266/moduos.c
+++ b/esp8266/moduos.c
@@ -97,6 +97,15 @@ STATIC mp_obj_t os_remove(mp_obj_t path_in) {
return vfs_proxy_call(MP_QSTR_remove, 1, &path_in);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_remove_obj, os_remove);
+
+STATIC mp_obj_t os_rename(mp_obj_t path_old, mp_obj_t path_new) {
+ mp_obj_t args[2];
+ args[0] = path_old;
+ args[1] = path_new;
+ return vfs_proxy_call(MP_QSTR_rename, 2, args);
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_2(os_rename_obj, os_rename);
+
#endif
STATIC mp_obj_t os_urandom(mp_obj_t num) {
@@ -130,6 +139,7 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_listdir), MP_ROM_PTR(&os_listdir_obj) },
{ MP_ROM_QSTR(MP_QSTR_mkdir), MP_ROM_PTR(&os_mkdir_obj) },
{ MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&os_remove_obj) },
+ { MP_ROM_QSTR(MP_QSTR_rename), MP_ROM_PTR(&os_rename_obj) },
#endif
};