Closed
Description
Basic Infos
- This issue complies with the issue POLICY doc.
- I have read the documentation at readthedocs and the issue is not addressed there.
- I have tested that the issue is present in current master branch (aka latest git).
- I have searched the issue tracker for a similar issue.
- If there is a stack dump, I have decoded it.
- I have filled out all fields below.
Platform
- Hardware: [ESP-12]
- Core Version: [ESP82xx Core 2.6.0-dev, NONOS SDK 2.2.2-dev(c0eb301), LWIP: 2.1.2 PUYA support]
- Development Env: [Platformio]
- Operating System: [Windows]
Settings in IDE
- Module: [Generic ESP8266 Module]
- Flash Mode: [dio]
- Flash Size: [4MB]
- lwip Variant: [v2 Lower Memory]
- Reset Method: [nodemcu]
- Flash Frequency: [40Mhz]
- CPU Frequency: [80Mhz]
- Upload Using: [OTA|SERIAL]
- Upload Speed: [115200] (serial upload only)
Problem Description
I know that SPIFFS may get fragmented, therefore I have a check to see if the write
to a file (append mode) on SPIFFS may return less than the number of bytes I want to write to it.
However, this check was never hit in my sketch.
I now have a check for file size before and after the write and this does show the bytes are not appended to my file when the SPIFFS is out of free sectors to write to.
size_t filesize = fw.size();
int bytesWriten = fw.write(&RTC_cache_data[0], RTC_cache.writePos);
if (bytesWriten < RTC_cache.writePos || fw.size() == filesize) {
String log = F("RTC : error writing file. Size before: ");
log += filesize;
log += F(" after: ");
log += fw.size();
log += F(" writen: ");
log += bytesWriten;
addLog(LOG_LEVEL_ERROR, log);
fw.close();
GarbageCollection();
writeerror = true;
return false;
}
N.B. fw
is a File fw;
This does result in errors like:
RTC : error writing file. Size before: 720 after: 720 written: 240
I guess the write
function should return the actual number of bytes written.
But on the other hand it may be that we're looking at some cache layer here?
Also replacement of data in a file will not result in a bigger file, but it may go unnoticed if the write was unsuccessful.
Metadata
Metadata
Assignees
Labels
No labels