Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0730e0e

Browse filesBrowse files
authored
Include nvs_commit() on three methods (espressif#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() ```
1 parent c45cff5 commit 0730e0e
Copy full SHA for 0730e0e

File tree

Expand file treeCollapse file tree

1 file changed

+13
-2
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+13
-2
lines changed

‎libraries/Preferences/src/Preferences.cpp

Copy file name to clipboardExpand all lines: libraries/Preferences/src/Preferences.cpp
+13-2Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
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

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.