FlashStorage icon indicating copy to clipboard operation
FlashStorage copied to clipboard

_Dirty is not reset after commit

Open Jan21493 opened this issue 6 years ago • 1 comments

I've seen #11 and agree with it. When a value is written (EEPROMClass::update), _dirty is set, because a commit is required to make this change persistent.

A commit only writes data to flash memory, if neccessary - equals to if _dirty is set and makes sense as well. But where is the _dirty flag cleared? Otherwise after the first call of EEPROMClass::update the _dirty is always true and makes no sense anymore.

I propose to clear the dirty flag at the end of the commit:

void EEPROMClass::commit()
{
  if (!_initialized) init();
  if (_dirty) {
    _eeprom.valid = true;
    eeprom_storage.write(_eeprom);
    _dirty = false;
  }
}

With this statement you may call commit even within a loop and it does not harm flash memory, because the data is actually only written to flash, if some data was changed with a EEPROMClass::update before.

Jan21493 avatar Jan 08 '19 23:01 Jan21493

@cmaglie How about a bugfix for this?

tuxedo0801 avatar Sep 26 '20 14:09 tuxedo0801