Fix transmit history file to get removed on factory reset

This commit is contained in:
Ben Meadors
2026-04-18 08:00:16 -05:00
parent d78e7b1ef9
commit 3fd6a9fba5
5 changed files with 115 additions and 38 deletions
+7
View File
@@ -17,6 +17,7 @@
#include "Router.h"
#include "SPILock.h"
#include "SafeFile.h"
#include "TransmitHistory.h"
#include "TypeConversions.h"
#include "error.h"
#include "main.h"
@@ -509,6 +510,12 @@ bool NodeDB::factoryReset(bool eraseBleBonds)
}
#endif
spiLock->unlock();
// rmDir above nuked the .dat file, but TransmitHistory's in-memory
// cache auto-flushes every 5 min and would resurrect it.
if (transmitHistory) {
transmitHistory->clear();
}
// second, install default state (this will deal with the duplicate mac address issue)
installDefaultNodeDatabase();
installDefaultDeviceState();
+21
View File
@@ -255,6 +255,21 @@ bool TransmitHistory::saveToDisk()
return false;
}
void TransmitHistory::clear()
{
history.clear();
lastMillis.clear();
dirty = false;
lastDiskSave = 0; // so the next legit broadcast persists immediately
spiLock->lock();
if (FSCom.exists(FILENAME)) {
FSCom.remove(FILENAME);
}
spiLock->unlock();
LOG_INFO("TransmitHistory: cleared in-memory state + on-disk file");
}
#else
// No filesystem available — provide stub with in-memory tracking
TransmitHistory *transmitHistory = nullptr;
@@ -290,4 +305,10 @@ bool TransmitHistory::saveToDisk()
return true;
}
void TransmitHistory::clear()
{
history.clear();
lastMillis.clear();
}
#endif
+7
View File
@@ -76,6 +76,13 @@ class TransmitHistory
*/
bool saveToDisk();
/**
* Wipe in-memory throttle state + remove the on-disk file. Required
* alongside rmDir("/prefs") in factoryReset — otherwise the 5-min
* auto-flush resurrects the file from the still-populated maps.
*/
void clear();
private:
TransmitHistory() = default;