Don't delete contents of /static unless tar is downloaded

This commit is contained in:
Jm Casler 2022-01-05 19:29:45 -08:00
parent 063d7a7d81
commit d5fc905402

View File

@ -689,6 +689,14 @@ void handleUpdateSPIFFS(HTTPRequest *req, HTTPResponse *res)
res->println("Downloading Meshtastic Web Content..."); res->println("Downloading Meshtastic Web Content...");
WiFiClientSecure *client = new WiFiClientSecure;
Stream *streamptr = getTarHTTPClientPtr(client, tarURL, certificate);
delay(5); // Let other network operations run
if (streamptr != nullptr) {
DEBUG_MSG("Connection to content server ... success!\n");
File root = SPIFFS.open("/"); File root = SPIFFS.open("/");
File file = root.openNextFile(); File file = root.openNextFile();
@ -703,12 +711,7 @@ void handleUpdateSPIFFS(HTTPRequest *req, HTTPResponse *res)
file = root.openNextFile(); file = root.openNextFile();
} }
// return; delay(5); // Let other network operations run
WiFiClientSecure *client = new WiFiClientSecure;
Stream *streamptr = getTarHTTPClientPtr(client, tarURL, certificate);
if (streamptr != nullptr) {
TarUnpacker *TARUnpacker = new TarUnpacker(); TarUnpacker *TARUnpacker = new TarUnpacker();
TARUnpacker->haltOnError(false); // stop on fail (manual restart/reset required) TARUnpacker->haltOnError(false); // stop on fail (manual restart/reset required)
@ -731,7 +734,10 @@ void handleUpdateSPIFFS(HTTPRequest *req, HTTPResponse *res)
} }
if (!TARUnpacker->tarStreamExpander(streamptr, streamSize, SPIFFS, "/static")) { if (!TARUnpacker->tarStreamExpander(streamptr, streamSize, SPIFFS, "/static")) {
res->printf("tarStreamExpander failed with return code #%d\n", TARUnpacker->tarGzGetError());
Serial.printf("tarStreamExpander failed with return code #%d\n", TARUnpacker->tarGzGetError()); Serial.printf("tarStreamExpander failed with return code #%d\n", TARUnpacker->tarGzGetError());
return;
} else { } else {
// print leftover bytes if any (probably zero-fill from the server) // print leftover bytes if any (probably zero-fill from the server)
while (http.connected()) { while (http.connected()) {
@ -744,7 +750,9 @@ void handleUpdateSPIFFS(HTTPRequest *req, HTTPResponse *res)
} }
} else { } else {
res->printf("Failed to establish http connection\n");
Serial.println("Failed to establish http connection"); Serial.println("Failed to establish http connection");
return;
} }
res->println("<a href=/>Done</a>"); res->println("<a href=/>Done</a>");