1
- // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
1
+ // Copyright 2015-2021 Espressif Systems (Shanghai) PTE LTD
2
2
//
3
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
4
// you may not use this file except in compliance with the License.
5
5
// You may obtain a copy of the License at
6
+
6
7
// http://www.apache.org/licenses/LICENSE-2.0
7
8
//
8
9
// 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_
43
44
}
44
45
err = nvs_open_from_partition (partition_label, name, readOnly ? NVS_READONLY : NVS_READWRITE, &_handle);
45
46
} else {
46
- err = nvs_open (name, readOnly? NVS_READONLY: NVS_READWRITE, &_handle);
47
+ err = nvs_open (name, readOnly ? NVS_READONLY : NVS_READWRITE, &_handle);
47
48
}
48
49
if (err){
49
50
log_e (" nvs_open failed: %s" , nvs_error (err));
@@ -74,6 +75,11 @@ bool Preferences::clear(){
74
75
log_e (" nvs_erase_all fail: %s" , nvs_error (err));
75
76
return false ;
76
77
}
78
+ err = nvs_commit (_handle);
79
+ if (err){
80
+ log_e (" nvs_commit fail: %s" , nvs_error (err));
81
+ return false ;
82
+ }
77
83
return true ;
78
84
}
79
85
@@ -90,6 +96,11 @@ bool Preferences::remove(const char * key){
90
96
log_e (" nvs_erase_key fail: %s %s" , key, nvs_error (err));
91
97
return false ;
92
98
}
99
+ err = nvs_commit (_handle);
100
+ if (err){
101
+ log_e (" nvs_commit fail: %s %s" , key, nvs_error (err));
102
+ return false ;
103
+ }
93
104
return true ;
94
105
}
95
106
0 commit comments