Skip to content
Snippets Groups Projects
Commit 7c004e79 authored by Robert HH's avatar Robert HH Committed by Paul Sokolovsky
Browse files

extmod/vfs_fat*: Replace text error messages by POSIX error numbers.

These changes are in line with similar changes in other modules, and
with standard Python interface.
parent 751e3b7a
No related branches found
No related tags found
No related merge requests found
...@@ -79,12 +79,11 @@ STATIC mp_obj_t fat_vfs_remove(mp_obj_t vfs_in, mp_obj_t path_in) { ...@@ -79,12 +79,11 @@ STATIC mp_obj_t fat_vfs_remove(mp_obj_t vfs_in, mp_obj_t path_in) {
const char *path = mp_obj_str_get_str(path_in); const char *path = mp_obj_str_get_str(path_in);
// TODO check that path is actually a file before trying to unlink it // TODO check that path is actually a file before trying to unlink it
FRESULT res = f_unlink(path); FRESULT res = f_unlink(path);
switch (res) { if (res == FR_OK) {
case FR_OK:
return mp_const_none; return mp_const_none;
default: } else {
// TODO: standard errno's nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError,
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "Error removing file '%s'", path)); MP_OBJ_NEW_SMALL_INT(fresult_to_errno_table[res])));
} }
} }
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);
...@@ -94,11 +93,11 @@ STATIC mp_obj_t fat_vfs_rename(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t path_ ...@@ -94,11 +93,11 @@ STATIC mp_obj_t fat_vfs_rename(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t path_
const char *old_path = mp_obj_str_get_str(path_in); const char *old_path = mp_obj_str_get_str(path_in);
const char *new_path = mp_obj_str_get_str(path_out); const char *new_path = mp_obj_str_get_str(path_out);
FRESULT res = f_rename(old_path, new_path); FRESULT res = f_rename(old_path, new_path);
switch (res) { if (res == FR_OK) {
case FR_OK:
return mp_const_none; return mp_const_none;
default: } else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "Error renaming file '%s' to '%s'", old_path, new_path)); nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError,
MP_OBJ_NEW_SMALL_INT(fresult_to_errno_table[res])));
} }
} }
...@@ -108,14 +107,11 @@ STATIC mp_obj_t fat_vfs_mkdir(mp_obj_t vfs_in, mp_obj_t path_o) { ...@@ -108,14 +107,11 @@ 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);
FRESULT res = f_mkdir(path); FRESULT res = f_mkdir(path);
switch (res) { if (res == FR_OK) {
case FR_OK:
return mp_const_none; return mp_const_none;
case FR_EXIST: } else {
// TODO should be FileExistsError nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError,
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "File exists: '%s'", path)); MP_OBJ_NEW_SMALL_INT(fresult_to_errno_table[res])));
default:
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "Error creating directory '%s'", path));
} }
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_mkdir_obj, fat_vfs_mkdir); STATIC MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_mkdir_obj, fat_vfs_mkdir);
......
...@@ -54,8 +54,9 @@ mp_obj_t fat_vfs_listdir(const char *path, bool is_str_type) { ...@@ -54,8 +54,9 @@ mp_obj_t fat_vfs_listdir(const char *path, bool is_str_type) {
res = f_opendir(&dir, path); /* Open the directory */ res = f_opendir(&dir, path); /* Open the directory */
if (res != FR_OK) { if (res != FR_OK) {
// TODO should be mp_type_FileNotFoundError nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError,
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "No such file or directory: '%s'", path)); MP_OBJ_NEW_SMALL_INT(fresult_to_errno_table[res])));
} }
mp_obj_t dir_list = mp_obj_new_list(0, NULL); mp_obj_t dir_list = mp_obj_new_list(0, NULL);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment