From 5ca4b9908ae499bc154b3ee4b64350a0895df27c Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Fri, 17 Feb 2017 12:10:00 -0800 Subject: [PATCH] Delete dataset from persistent storage when clearing. (#1332) --- src/core/meshcop/dataset.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/core/meshcop/dataset.cpp b/src/core/meshcop/dataset.cpp index 43a191655..d2108b4d7 100644 --- a/src/core/meshcop/dataset.cpp +++ b/src/core/meshcop/dataset.cpp @@ -440,8 +440,19 @@ ThreadError Dataset::Restore(void) ThreadError Dataset::Store(void) { - return otPlatSettingsSet(mInstance, static_cast(mType == Tlv::kActiveTimestamp ? kKeyActiveDataset : - kKeyPendingDataset), mTlvs, mLength); + uint16_t key = static_cast((mType == Tlv::kActiveTimestamp) ? kKeyActiveDataset : kKeyPendingDataset); + ThreadError error; + + if (mLength == 0) + { + error = otPlatSettingsDelete(mInstance, key, 0); + } + else + { + error = otPlatSettingsSet(mInstance, key, mTlvs, mLength); + } + + return error; } ThreadError Dataset::Set(const Tlv &aTlv)