fixed stupid persistent contacts saved bug in datastore; prelim contacts discovery function

This commit is contained in:
pelgraine
2026-03-04 07:16:07 +11:00
parent d92fdc9ffe
commit fe949235d9
8 changed files with 379 additions and 7 deletions
+9 -2
View File
@@ -405,11 +405,15 @@ void DataStore::saveContacts(DataStoreHost* host) {
idx++;
}
size_t bytesWritten = file.size();
file.close();
// --- Step 2: Verify the write completed ---
// Reopen read-only to get true on-disk size (SPIFFS file.size() is unreliable before close)
size_t expectedBytes = recordsWritten * 152; // 152 bytes per contact record
File verify = openRead(fs, tmpPath);
size_t bytesWritten = verify ? verify.size() : 0;
if (verify) verify.close();
if (!writeOk || bytesWritten != expectedBytes) {
Serial.printf("DataStore: saveContacts ABORTED — wrote %d bytes, expected %d (%d records)\n",
(int)bytesWritten, (int)expectedBytes, recordsWritten);
@@ -493,10 +497,13 @@ void DataStore::saveChannels(DataStoreHost* host) {
channel_idx++;
}
size_t bytesWritten = file.size();
file.close();
// Reopen read-only to get true on-disk size (SPIFFS file.size() is unreliable before close)
size_t expectedBytes = channel_idx * 68; // 4 + 32 + 32 = 68 bytes per channel
File verify = openRead(fs, tmpPath);
size_t bytesWritten = verify ? verify.size() : 0;
if (verify) verify.close();
if (!writeOk || bytesWritten != expectedBytes) {
Serial.printf("DataStore: saveChannels ABORTED — wrote %d bytes, expected %d\n",
(int)bytesWritten, (int)expectedBytes);