Merge branch 'bugfix/nvs_fix_erase_any_v3.1' into 'release/v3.1'

nvs_flash: Multi-page blob erased using nvs_erase_key should be cleaned properly (v3.1)

See merge request idf/esp-idf!4818
This commit is contained in:
Jiang Jiang Jian 2019-04-28 22:12:12 +08:00
commit 3004d86dc1
2 changed files with 22 additions and 0 deletions

View file

@ -593,6 +593,12 @@ esp_err_t Storage::eraseItem(uint8_t nsIndex, ItemType datatype, const char* key
return err; return err;
} }
#ifdef CONFIG_MP_BLOB_SUPPORT
if (item.datatype == ItemType::BLOB_DATA || item.datatype == ItemType::BLOB_IDX) {
return eraseMultiPageBlob(nsIndex, key);
}
#endif
return findPage->eraseItem(nsIndex, datatype, key); return findPage->eraseItem(nsIndex, datatype, key);
} }

View file

@ -1776,6 +1776,22 @@ TEST_CASE("Modification from multi-page to single page", "[nvs]")
nvs_close(handle); nvs_close(handle);
} }
TEST_CASE("Multi-page blob erased using nvs_erase_key should not be found when probed for just length", "[nvs]")
{
const size_t blob_size = Page::CHUNK_MAX_SIZE *3;
uint8_t blob[blob_size] = {0};
size_t read_size = blob_size;
SpiFlashEmulator emu(5);
TEST_ESP_OK(nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, 0, 5));
nvs_handle handle;
TEST_ESP_OK(nvs_open("Test", NVS_READWRITE, &handle));
TEST_ESP_OK(nvs_set_blob(handle, "abc", blob, blob_size));
TEST_ESP_OK(nvs_erase_key(handle, "abc"));
TEST_ESP_ERR(nvs_get_blob(handle, "abc", NULL, &read_size), ESP_ERR_NVS_NOT_FOUND);
TEST_ESP_OK(nvs_commit(handle));
nvs_close(handle);
}
TEST_CASE("Check that orphaned blobs are erased during init", "[nvs]") TEST_CASE("Check that orphaned blobs are erased during init", "[nvs]")
{ {