extmod/vfs_fat: Add .rename() method.
This commit is contained in:
parent
09e363316f
commit
e0821830b0
|
@ -89,6 +89,21 @@ STATIC mp_obj_t fat_vfs_remove(mp_obj_t vfs_in, mp_obj_t path_in) {
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_remove_obj, fat_vfs_remove);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_remove_obj, fat_vfs_remove);
|
||||||
|
|
||||||
|
STATIC mp_obj_t fat_vfs_rename(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t path_out) {
|
||||||
|
(void)vfs_in;
|
||||||
|
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);
|
||||||
|
switch (res) {
|
||||||
|
case FR_OK:
|
||||||
|
return mp_const_none;
|
||||||
|
default:
|
||||||
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "Error renaming file '%s' to '%s'", old_path, new_path));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
STATIC MP_DEFINE_CONST_FUN_OBJ_3(fat_vfs_rename_obj, fat_vfs_rename);
|
||||||
|
|
||||||
STATIC mp_obj_t fat_vfs_mkdir(mp_obj_t vfs_in, mp_obj_t path_o) {
|
STATIC mp_obj_t fat_vfs_mkdir(mp_obj_t vfs_in, mp_obj_t path_o) {
|
||||||
(void)vfs_in;
|
(void)vfs_in;
|
||||||
const char *path = mp_obj_str_get_str(path_o);
|
const char *path = mp_obj_str_get_str(path_o);
|
||||||
|
@ -111,6 +126,7 @@ STATIC const mp_rom_map_elem_t fat_vfs_locals_dict_table[] = {
|
||||||
{ MP_ROM_QSTR(MP_QSTR_listdir), MP_ROM_PTR(&fat_vfs_listdir_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_listdir), MP_ROM_PTR(&fat_vfs_listdir_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_mkdir), MP_ROM_PTR(&fat_vfs_mkdir_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_mkdir), MP_ROM_PTR(&fat_vfs_mkdir_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&fat_vfs_remove_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&fat_vfs_remove_obj) },
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_rename), MP_ROM_PTR(&fat_vfs_rename_obj) },
|
||||||
};
|
};
|
||||||
STATIC MP_DEFINE_CONST_DICT(fat_vfs_locals_dict, fat_vfs_locals_dict_table);
|
STATIC MP_DEFINE_CONST_DICT(fat_vfs_locals_dict, fat_vfs_locals_dict_table);
|
||||||
|
|
||||||
|
|
|
@ -719,6 +719,7 @@ Q(umount)
|
||||||
Q(readonly)
|
Q(readonly)
|
||||||
Q(mkfs)
|
Q(mkfs)
|
||||||
Q(listdir)
|
Q(listdir)
|
||||||
|
Q(rename)
|
||||||
Q(readblocks)
|
Q(readblocks)
|
||||||
Q(writeblocks)
|
Q(writeblocks)
|
||||||
Q(ioctl)
|
Q(ioctl)
|
||||||
|
|
Loading…
Reference in New Issue