bufgix: prevent file data loss due to replacing an open file pointer
partial fix for #5275
This commit is contained in:
@@ -38,7 +38,7 @@ void closeFile() {
|
|||||||
DEBUGFS_PRINT(F("Close -> "));
|
DEBUGFS_PRINT(F("Close -> "));
|
||||||
uint32_t s = millis();
|
uint32_t s = millis();
|
||||||
#endif
|
#endif
|
||||||
f.close();
|
if (f) f.close(); // only close if we have an open file
|
||||||
DEBUGFS_PRINTF("took %lu ms\n", millis() - s);
|
DEBUGFS_PRINTF("took %lu ms\n", millis() - s);
|
||||||
doCloseFile = false;
|
doCloseFile = false;
|
||||||
}
|
}
|
||||||
@@ -271,6 +271,8 @@ bool writeObjectToFile(const char* file, const char* key, const JsonDocument* co
|
|||||||
s = millis();
|
s = millis();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (doCloseFile) closeFile(); // This prevents the loss of file data that is still cached in the File object.
|
||||||
|
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
char fileName[129]; strncpy_P(fileName, file, 128); fileName[128] = 0; //use PROGMEM safe copy as FS.open() does not
|
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+");
|
f = WLED_FS.open(fileName, WLED_FS.exists(fileName) ? "r+" : "w+");
|
||||||
|
|||||||
Reference in New Issue
Block a user