Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion wled00/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void closeFile() {
DEBUGFS_PRINT(F("Close -> "));
uint32_t s = millis();
#endif
f.close();
f.close(); // "if (f)" check is aleady done inside f.close(), and f cannot be nullptr -> no need for double checking before closing the file handle.
DEBUGFS_PRINTF("took %lu ms\n", millis() - s);
doCloseFile = false;
}
Expand Down Expand Up @@ -271,6 +271,8 @@ bool writeObjectToFile(const char* file, const char* key, const JsonDocument* co
s = millis();
#endif

if (doCloseFile) closeFile(); // This prevents the loss of file data that is still cached in the File object.

size_t pos = 0;
char fileName[129]; strncpy_P(fileName, file, 128); fileName[128] = 0; //use PROGMEM safe copy as FS.open() does not
f = WLED_FS.open(fileName, WLED_FS.exists(fileName) ? "r+" : "w+");
Expand Down