Skip to content

Commit

Permalink
improve error handling in IO module
Browse files Browse the repository at this point in the history
  • Loading branch information
ofabel committed Oct 2, 2024
1 parent 042d0bd commit 89f2026
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/micropython
21 changes: 8 additions & 13 deletions lib/micropython-port/mp_flipper_fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,32 @@ inline void* mp_flipper_file_open(const char* name, uint8_t access_mode, uint8_t

do {
if(mp_flipper_try_resolve_filesystem_path(path) == MP_FLIPPER_IMPORT_STAT_NO_EXIST) {
mp_flipper_raise_os_error_with_filename(MP_ENOENT, name);

break;
}

if(!storage_file_open(file, furi_string_get_cstr(path), access_mode, open_mode)) {
mp_flipper_raise_os_error_with_filename(MP_ENOENT, name);

break;
}
} while(false);

// TODO close open files upon application exit
if(!storage_file_is_open(file)) {
storage_file_close(file);
storage_file_free(file);

return NULL;
}

return file;
}

inline bool mp_flipper_file_close(void* handle) {
mp_flipper_context_t* ctx = mp_flipper_context;

File* file = handle;

if(storage_file_is_open(file) && storage_file_close(file)) {
// NOP
} else {
// TODO handle error
}
bool success = storage_file_is_open(file) && storage_file_close(file);

storage_file_free(file);

return true;
return success;
}

inline size_t mp_flipper_file_seek(void* handle, uint32_t offset) {
Expand Down

0 comments on commit 89f2026

Please sign in to comment.