Skip to content

Commit e6e1b81

Browse files
committed
add DataStore::deleteBlobByKey()
1 parent 06a83c0 commit e6e1b81

3 files changed

Lines changed: 19 additions & 0 deletions

File tree

examples/companion_radio/DataStore.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,9 @@ bool DataStore::putBlobByKey(const uint8_t key[], int key_len, const uint8_t src
560560
}
561561
return false; // error
562562
}
563+
bool DataStore::deleteBlobByKey(const uint8_t key[], int key_len) {
564+
return true; // this is just a stub on NRF52/STM32 platforms
565+
}
563566
#else
564567
uint8_t DataStore::getBlobByKey(const uint8_t key[], int key_len, uint8_t dest_buf[]) {
565568
char path[64];
@@ -598,4 +601,17 @@ bool DataStore::putBlobByKey(const uint8_t key[], int key_len, const uint8_t src
598601
}
599602
return false; // error
600603
}
604+
605+
bool DataStore::deleteBlobByKey(const uint8_t key[], int key_len) {
606+
char path[64];
607+
char fname[18];
608+
609+
if (key_len > 8) key_len = 8; // just use first 8 bytes (prefix)
610+
mesh::Utils::toHex(fname, key, key_len);
611+
sprintf(path, "/bl/%s", fname);
612+
613+
_fs->remove(path);
614+
615+
return true; // return true even if file did not exist
616+
}
601617
#endif

examples/companion_radio/DataStore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class DataStore {
4242
void migrateToSecondaryFS();
4343
uint8_t getBlobByKey(const uint8_t key[], int key_len, uint8_t dest_buf[]);
4444
bool putBlobByKey(const uint8_t key[], int key_len, const uint8_t src_buf[], uint8_t len);
45+
bool deleteBlobByKey(const uint8_t key[], int key_len);
4546
File openRead(const char* filename);
4647
File openRead(FILESYSTEM* fs, const char* filename);
4748
bool removeFile(const char* filename);

examples/companion_radio/MyMesh.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ bool MyMesh::shouldOverwriteWhenFull() const {
307307
}
308308

309309
void MyMesh::onContactOverwrite(const uint8_t* pub_key) {
310+
_store->deleteBlobByKey(pub_key, PUB_KEY_SIZE); // delete from storage
310311
if (_serial->isConnected()) {
311312
out_frame[0] = PUSH_CODE_CONTACT_DELETED;
312313
memcpy(&out_frame[1], pub_key, PUB_KEY_SIZE);
@@ -1124,6 +1125,7 @@ void MyMesh::handleCmdFrame(size_t len) {
11241125
uint8_t *pub_key = &cmd_frame[1];
11251126
ContactInfo *recipient = lookupContactByPubKey(pub_key, PUB_KEY_SIZE);
11261127
if (recipient && removeContact(*recipient)) {
1128+
_store->deleteBlobByKey(pub_key, PUB_KEY_SIZE);
11271129
dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY);
11281130
writeOKFrame();
11291131
} else {

0 commit comments

Comments
 (0)