Skip to content

Commit 5d5cd1d

Browse files
Clear updater state on any error (#6325)
Fixes #2090 The Updater checks that an update isn't already in progress on ::begin, but when an error happens in the middle of an upload it's impossible to actually reset this flag w/o a reboot. Reset the state members (esp. _size) on any error condition so that you can restart the transfer with a new ::begin. Any error condition is fatal, anyway, so there is no reason not to clear the current state at that point.
1 parent 93ef2e2 commit 5d5cd1d

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

cores/esp8266/Updater.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ bool UpdaterClass::end(bool evenIfRemaining){
205205
#endif
206206
if (sigLen != _verify->length()) {
207207
_setError(UPDATE_ERROR_SIGN);
208-
_reset();
209208
return false;
210209
}
211210

@@ -231,7 +230,6 @@ bool UpdaterClass::end(bool evenIfRemaining){
231230
uint8_t *sig = (uint8_t*)malloc(sigLen);
232231
if (!sig) {
233232
_setError(UPDATE_ERROR_SIGN);
234-
_reset();
235233
return false;
236234
}
237235
ESP.flashRead(_startAddress + binSize, (uint32_t *)sig, sigLen);
@@ -244,7 +242,6 @@ bool UpdaterClass::end(bool evenIfRemaining){
244242
#endif
245243
if (!_verify->verify(_hash, (void *)sig, sigLen)) {
246244
_setError(UPDATE_ERROR_SIGN);
247-
_reset();
248245
return false;
249246
}
250247
#ifdef DEBUG_UPDATER
@@ -254,7 +251,6 @@ bool UpdaterClass::end(bool evenIfRemaining){
254251
_md5.calculate();
255252
if (strcasecmp(_target_md5.c_str(), _md5.toString().c_str())) {
256253
_setError(UPDATE_ERROR_MD5);
257-
_reset();
258254
return false;
259255
}
260256
#ifdef DEBUG_UPDATER
@@ -467,7 +463,6 @@ size_t UpdaterClass::writeStream(Stream &data) {
467463
if(toRead == 0) { //Timeout
468464
_currentAddress = (_startAddress + _size);
469465
_setError(UPDATE_ERROR_STREAM);
470-
_reset();
471466
return written;
472467
}
473468
}
@@ -494,6 +489,7 @@ void UpdaterClass::_setError(int error){
494489
#ifdef DEBUG_UPDATER
495490
printError(DEBUG_UPDATER);
496491
#endif
492+
_reset(); // Any error condition invalidates the entire update, so clear partial status
497493
}
498494

499495
void UpdaterClass::printError(Print &out){

0 commit comments

Comments
 (0)