mirror of
https://github.com/alexhopeoconnor/firmware.git
synced 2026-10-18 17:31:42 +10:00
Fix transmit history file to get removed on factory reset
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user