Skip to content

Commit 77d7597

Browse files
committed
Resolve LittleFS path ambiguity
1 parent 265a235 commit 77d7597

File tree

5 files changed

+21
-17
lines changed

5 files changed

+21
-17
lines changed

src/lib/LR1121Driver/LR1121.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "LR1121_hal.h"
44
#include "logging.h"
55

6-
#include <SPIFFS.h>
6+
#include <LittleFS.h>
77
#include <SPIEx.h>
88

99
#define LR1121_FIRMWARE_TYPE 0xF3
@@ -70,7 +70,7 @@ void LR1121Driver::End()
7070
bool LR1121Driver::CheckVersion(const SX12XX_Radio_Number_t radioNumber)
7171
{
7272
firmware_version_t version = GetFirmwareVersion(radioNumber);
73-
if (!SPIFFS.exists("/lr1121.txt") && (version.type != LR1121_FIRMWARE_TYPE || version.version != LR11XX_FIRMWARE_VERSION))
73+
if (!LittleFS.exists("/lr1121.txt") && (version.type != LR1121_FIRMWARE_TYPE || version.version != LR11XX_FIRMWARE_VERSION))
7474
{
7575
DBGLN("Upgrading radio #%d", radioNumber);
7676
// do upgrade

src/lib/OPTIONS/hardware.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static String builtinHardwareConfig;
146146

147147
String& getHardware()
148148
{
149-
File file = LittleFS.open("hardware.json", "r");
149+
File file = LittleFS.open("/hardware.json", "r");
150150
if (!file || file.isDirectory())
151151
{
152152
if (file)
@@ -222,7 +222,7 @@ bool hardware_init(EspFlashStream &strmFlash)
222222

223223
Stream *strmSrc;
224224
JsonDocument doc;
225-
File file = LittleFS.open("hardware.json", "r");
225+
File file = LittleFS.open("/hardware.json", "r");
226226
if (!file || file.isDirectory()) {
227227
constexpr size_t hardwareConfigOffset = ELRSOPTS_PRODUCTNAME_SIZE + ELRSOPTS_DEVICENAME_SIZE + ELRSOPTS_OPTIONS_SIZE;
228228
strmFlash.setPosition(hardwareConfigOffset);

src/lib/OPTIONS/options.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void saveOptions(Stream &stream, bool customised)
9797

9898
void saveOptions()
9999
{
100-
File options = LittleFS.open("options.json", "w");
100+
File options = LittleFS.open("/options.json", "w");
101101
saveOptions(options, true);
102102
options.close();
103103
}
@@ -143,7 +143,7 @@ static void options_LoadFromFlashOrFile(EspFlashStream &strmFlash)
143143
}
144144

145145
// load options.json from the SPIFFS partition
146-
File file = LittleFS.open("options.json", "r");
146+
File file = LittleFS.open("/options.json", "r");
147147
if (file && !file.isDirectory())
148148
{
149149
DeserializationError error = deserializeJson(spiffsDoc, file);
@@ -218,7 +218,7 @@ void options_SetTrueDefaults()
218218
doc["domain"] = firmwareOptions.domain;
219219
doc["flash-discriminator"] = firmwareOptions.flash_discriminator;
220220

221-
File options = LittleFS.open("options.json", "w");
221+
File options = LittleFS.open("/options.json", "w");
222222
serializeJson(doc, options);
223223
options.close();
224224
}

src/lib/WIFI/devWIFI.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,17 @@ static void putFile(AsyncWebServerRequest *request, uint8_t *data, size_t len, s
171171
{
172172
static File file;
173173
static size_t bytes;
174-
if (!file || request->url() != file.name()) {
174+
if (!file ||
175+
// Request URI starts with a / and LittleFS File::name() does not include it, ESP32 doesn't have File::fullName()
176+
strcmp(&request->url().c_str()[1], file.name()) != 0)
177+
{
175178
file = LittleFS.open(request->url(), "w");
176179
bytes = 0;
177180
}
178181
file.write(data, len);
179182
bytes += len;
180-
if (bytes == total) {
183+
if (bytes == total)
184+
{
181185
file.close();
182186
}
183187
}
@@ -204,18 +208,18 @@ static void HandleReboot(AsyncWebServerRequest *request)
204208
static void HandleReset(AsyncWebServerRequest *request)
205209
{
206210
if (request->hasArg("hardware")) {
207-
LittleFS.remove("hardware.json");
211+
LittleFS.remove("/hardware.json");
208212
}
209213
if (request->hasArg("options")) {
210-
LittleFS.remove("options.json");
214+
LittleFS.remove("/options.json");
211215
#if defined(TARGET_RX)
212216
config.SetModelId(255);
213217
config.SetForceTlmOff(false);
214218
config.Commit();
215219
#endif
216220
}
217221
if (request->hasArg("lr1121")) {
218-
LittleFS.remove("lr1121.txt");
222+
LittleFS.remove("/lr1121.txt");
219223
}
220224
if (request->hasArg("model") || request->hasArg("config")) {
221225
config.SetDefaults(true);
@@ -233,7 +237,7 @@ static void UpdateSettings(AsyncWebServerRequest *request, JsonVariant &json)
233237
return;
234238
}
235239

236-
File file = LittleFS.open("options.json", "w");
240+
File file = LittleFS.open("/options.json", "w");
237241
serializeJson(json, file);
238242
file.close();
239243
String options;
@@ -1073,7 +1077,7 @@ static void startServices()
10731077
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Methods", "POST,GET,OPTIONS");
10741078
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Headers", "*");
10751079

1076-
server.on("/hardware.json", HTTP_GET, getFile, nullptr, putFile);
1080+
server.on("/hardware.json", HTTP_GET | HTTP_POST, getFile, nullptr, putFile);
10771081
server.on("/options.json", HTTP_GET, getFile);
10781082
server.on("/reboot", HandleReboot);
10791083
server.on("/reset", HandleReset);

src/lib/WIFI/lr1121.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ static void WebUploadLR1121ResponseHandler(AsyncWebServerRequest *request)
2626
{
2727
msg = String(R"({"status": "ok", "msg": "Update complete. Refresh page to see new version information."})");
2828
// add tag file for lr1121 custom firmware
29-
if (!LittleFS.exists("lr1121.txt"))
29+
if (!LittleFS.exists("/lr1121.txt"))
3030
{
31-
File tagFile = LittleFS.open("lr1121.txt", "w");
31+
File tagFile = LittleFS.open("/lr1121.txt", "w");
3232
tagFile.close();
3333
}
3434
DBGLN("Update complete");
@@ -86,7 +86,7 @@ static void GetLR1121Status(AsyncWebServerRequest *request)
8686
hal.end();
8787
hal.init();
8888
hal.reset();
89-
json["manual"] = LittleFS.exists("lr1121.txt");
89+
json["manual"] = LittleFS.exists("/lr1121.txt");
9090
ReadStatusForRadio(json["radio1"].to<JsonObject>(), SX12XX_Radio_1);
9191
if (GPIO_PIN_NSS_2 != UNDEF_PIN)
9292
{

0 commit comments

Comments
 (0)