Skip to content

Update Preferences.cpp to include nvs_commit() on three methods #4972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
beamholder opened this issue Mar 23, 2021 · 8 comments
Closed

Update Preferences.cpp to include nvs_commit() on three methods #4972

beamholder opened this issue Mar 23, 2021 · 8 comments
Labels
Status: Stale Issue is stale stage (outdated/stuck)

Comments

@beamholder
Copy link
Contributor

In 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
when using

nvs_erase_all()
nvs_erase_key()
nvs_close()

Suggested changes:

void Preferences::end(){                                         // modified to add an nvs_commit()
    if(!_started){
        return;
    }
    esp_err_t err = nvs_commit(_handle);                         // to undo changes: delete the lines from here...
    if(err){
        log_e("nvs_commit fail: %s %s", key, nvs_error(err));
    }                                                            // to here.
    nvs_close(_handle);
    _started = false;
}
bool Preferences::clear(){                                  // modified to add an nvs_commit()
    if(!_started || _readOnly){
        return false;
    }
    esp_err_t err = nvs_erase_all(_handle);
    if(err){
        log_e("nvs_erase_all fail: %s", nvs_error(err));
        return false;
    }
    // return true;                                         // to undo changes: uncomment this line and...
    err = nvs_commit(_handle);                              // delete the lines from from here...
    if(err){
        log_e("nvs_commit fail: %s %s", key, nvs_error(err));
        return false;
    }
    return true;                                            // to here.
}
bool Preferences::remove(const char * key){                 // modified to add an nvs_commit()
    if(!_started || !key || _readOnly){
        return false;
    }
    esp_err_t err = nvs_erase_key(_handle, key);
    if(err){
        log_e("nvs_erase_key fail: %s %s", key, nvs_error(err));
        return false;
    }
    // return true;                                         // to undo changes: uncomment this line and...
    err = nvs_commit(_handle);                              // delete the lines from from here...
    if(err){
        log_e("nvs_commit fail: %s %s", key, nvs_error(err));
        return false;
    }
    return true;                                            // to here.
}
@Xylopyrographer
Copy link
Contributor

Correction to my suggested changes for the end() and clear() methods to fix a coding error in writing to log_e().

void Preferences::end(){                                         // modified to add an nvs_commit()
    if(!_started){
        return;
    }
    esp_err_t err = nvs_commit(_handle);                         // to undo changes: delete the lines from here...
    if(err){
        log_e("nvs_commit fail: %s", nvs_error(err));            // 2021-04-12: corrected this line 
    }                                                            // to here.
    nvs_close(_handle);
    _started = false;
}

and

/*
 * Clear all keys in opened preferences
 * */

bool Preferences::clear(){                                  // modified to add an nvs_commit()
    if(!_started || _readOnly){
        return false;
    }
    esp_err_t err = nvs_erase_all(_handle);
    if(err){
        log_e("nvs_erase_all fail: %s", nvs_error(err));
        return false;
    }
    // return true;                                         // to undo changes: uncomment this line and...
    err = nvs_commit(_handle);                              // delete the lines from from here...
    if(err){
        log_e("nvs_commit fail: %s", nvs_error(err));       // 2021-04-12: corrected this line
        return false;
    }
    return true;                                            // to here.
}

@stale
Copy link

stale bot commented Jun 18, 2021

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Stale Issue is stale stage (outdated/stuck) label Jun 18, 2021
@Xylopyrographer
Copy link
Contributor

Bump.

What is the review process? Thanks.

@lbernstone
Copy link
Contributor

You closed the pull request. The review process only happens on active pull requests 😄

@beamholder
Copy link
Contributor Author

beamholder commented Jun 19, 2021 via email

@stale
Copy link

stale bot commented Jun 19, 2021

[STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it openin the future.

@stale stale bot removed the Status: Stale Issue is stale stage (outdated/stuck) label Jun 19, 2021
@stale
Copy link

stale bot commented Aug 21, 2021

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Stale Issue is stale stage (outdated/stuck) label Aug 21, 2021
@stale
Copy link

stale bot commented Sep 19, 2021

[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.

@stale stale bot closed this as completed Sep 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Stale Issue is stale stage (outdated/stuck)
Projects
None yet
Development

No branches or pull requests

3 participants