1- // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
1+ // Copyright 2015-2021 Espressif Systems (Shanghai) PTE LTD
22//
33// Licensed under the Apache License, Version 2.0 (the "License");
44// you may not use this file except in compliance with the License.
55// You may obtain a copy of the License at
6+
67// http://www.apache.org/licenses/LICENSE-2.0
78//
89// Unless required by applicable law or agreed to in writing, software
@@ -43,7 +44,7 @@ bool Preferences::begin(const char * name, bool readOnly, const char* partition_
4344 }
4445 err = nvs_open_from_partition (partition_label, name, readOnly ? NVS_READONLY : NVS_READWRITE, &_handle);
4546 } else {
46- err = nvs_open (name, readOnly? NVS_READONLY: NVS_READWRITE, &_handle);
47+ err = nvs_open (name, readOnly ? NVS_READONLY : NVS_READWRITE, &_handle);
4748 }
4849 if (err){
4950 log_e (" nvs_open failed: %s" , nvs_error (err));
@@ -74,6 +75,11 @@ bool Preferences::clear(){
7475 log_e (" nvs_erase_all fail: %s" , nvs_error (err));
7576 return false ;
7677 }
78+ err = nvs_commit (_handle);
79+ if (err){
80+ log_e (" nvs_commit fail: %s" , nvs_error (err));
81+ return false ;
82+ }
7783 return true ;
7884}
7985
@@ -90,6 +96,11 @@ bool Preferences::remove(const char * key){
9096 log_e (" nvs_erase_key fail: %s %s" , key, nvs_error (err));
9197 return false ;
9298 }
99+ err = nvs_commit (_handle);
100+ if (err){
101+ log_e (" nvs_commit fail: %s %s" , key, nvs_error (err));
102+ return false ;
103+ }
93104 return true ;
94105}
95106
0 commit comments