Unverified Commit 0730e0ec authored by beamholder's avatar beamholder Committed by GitHub

Include nvs_commit() on three methods (#5309)

* Include nvs_commit() on three methods

In [Preferences.cpp](https://github.com/espressif/arduino-esp32/blob/master/libraries/Preferences/src/Preferences.cpp),  the functions:
```
Preferences::clear()
Preferences::remove()
Preferences::end()
```
should be revised to include a call to 
`nvs_commit()`
as required per 
[Non-volatile storage library](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/storage/nvs_flash.html)
when using 
```
nvs_erase_all()
nvs_erase_key()
nvs_close()
```
parent c45cff5f
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD // Copyright 2015-2021 Espressif Systems (Shanghai) PTE LTD
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
// //
// Unless required by applicable law or agreed to in writing, software // 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,7 +44,7 @@ bool Preferences::begin(const char * name, bool readOnly, const char* partition_
} }
err = nvs_open_from_partition(partition_label, name, readOnly ? NVS_READONLY : NVS_READWRITE, &_handle); err = nvs_open_from_partition(partition_label, name, readOnly ? NVS_READONLY : NVS_READWRITE, &_handle);
} else { } else {
err = nvs_open(name, readOnly?NVS_READONLY:NVS_READWRITE, &_handle); err = nvs_open(name, readOnly ? NVS_READONLY : NVS_READWRITE, &_handle);
} }
if(err){ if(err){
log_e("nvs_open failed: %s", nvs_error(err)); log_e("nvs_open failed: %s", nvs_error(err));
...@@ -74,6 +75,11 @@ bool Preferences::clear(){ ...@@ -74,6 +75,11 @@ bool Preferences::clear(){
log_e("nvs_erase_all fail: %s", nvs_error(err)); log_e("nvs_erase_all fail: %s", nvs_error(err));
return false; return false;
} }
err = nvs_commit(_handle);
if(err){
log_e("nvs_commit fail: %s", nvs_error(err));
return false;
}
return true; return true;
} }
...@@ -90,6 +96,11 @@ bool Preferences::remove(const char * key){ ...@@ -90,6 +96,11 @@ bool Preferences::remove(const char * key){
log_e("nvs_erase_key fail: %s %s", key, nvs_error(err)); log_e("nvs_erase_key fail: %s %s", key, nvs_error(err));
return false; return false;
} }
err = nvs_commit(_handle);
if(err){
log_e("nvs_commit fail: %s %s", key, nvs_error(err));
return false;
}
return true; return true;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment