Przeglądaj źródła

improve error handling in IO module

Oliver Fabel 1 rok temu
rodzic
commit
89f202678d
2 zmienionych plików z 9 dodań i 14 usunięć
  1. 1 1
      lib/micropython
  2. 8 13
      lib/micropython-port/mp_flipper_fileio.c

+ 1 - 1
lib/micropython

@@ -1 +1 @@
-Subproject commit 69839afcf5230388ceb9c88da7ffc6bd3c1c4a0a
+Subproject commit 4aff18dad530e1afbe235fc28b981c3e6de296e4

+ 8 - 13
lib/micropython-port/mp_flipper_fileio.c

@@ -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) {