Skip to content

Commit 6a9bcbf

Browse files
committed
Fix orphan blob accumulation on firmware upgrade
Before PR#1495, blobs were written for every advert regardless of whether the advertiser became a contact. Nodes upgrading from older firmware (e.g., v1.11.0) have thousands of orphan blobs consuming storage space. This adds a one-time cleanup on first boot that: - Iterates all blob files in /bl/ - Deletes any blob that doesn't match a current contact's pub_key - Creates a marker file to prevent running again Affects ESP32 and RP2040 platforms (which use /bl/ directory).
1 parent f7e92a7 commit 6a9bcbf

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

examples/companion_radio/MyMesh.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,35 @@ void MyMesh::begin(bool has_display) {
864864
resetContacts();
865865
_store->loadContacts(this);
866866
bootstrapRTCfromContacts();
867+
868+
#if defined(ESP32) || defined(RP2040_PLATFORM)
869+
// One-time cleanup of orphan blobs from pre-v1.13 firmware
870+
FILESYSTEM* fs = _store->getPrimaryFS();
871+
if (!fs->exists("/bl/.cleaned")) {
872+
MESH_DEBUG_PRINTLN("Cleaning orphan blobs...");
873+
File root = _store->openRead("/bl");
874+
if (root) {
875+
for (File f = root.openNextFile(); f; f = root.openNextFile()) {
876+
const char* name = f.name();
877+
f.close();
878+
uint8_t key[8];
879+
if (name[0] != '.' && strlen(name) == 16 && mesh::Utils::fromHex(key, 8, name)) {
880+
bool found = false;
881+
for (int i = 0; i < num_contacts && !found; i++)
882+
found = (memcmp(contacts[i].id.pub_key, key, 8) == 0);
883+
if (!found) _store->deleteBlobByKey(key, 8);
884+
}
885+
}
886+
root.close();
887+
}
888+
#if defined(ESP32)
889+
File m = fs->open("/bl/.cleaned", "w", true);
890+
#else
891+
File m = fs->open("/bl/.cleaned", "w");
892+
#endif
893+
if (m) m.close();
894+
}
895+
#endif
867896
addChannel("Public", PUBLIC_GROUP_PSK); // pre-configure Andy's public channel
868897
_store->loadChannels(this);
869898

0 commit comments

Comments
 (0)