Skip to content

Commit b9b9c1b

Browse files
authored
Upgrade e32 4.3.0 (#303)
* fix system reset service for esp32 * make missing directories when saving files
1 parent 004659b commit b9b9c1b

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

lib/framework/ESPFS.h

+5
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1+
#ifndef ESPFS_H_
2+
#define ESPFS_H_
3+
14
#include <LittleFS.h>
25
#define ESPFS LittleFS
6+
7+
#endif

lib/framework/FSPersistence.h

+16
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ class FSPersistence {
5151
JsonObject jsonObject = jsonDocument.to<JsonObject>();
5252
_statefulService->read(jsonObject, _stateReader);
5353

54+
// make directories if required
55+
mkdirs();
56+
5457
// serialize it to filesystem
5558
File settingsFile = _fs->open(_filePath, "w");
5659

@@ -87,6 +90,19 @@ class FSPersistence {
8790
size_t _bufferSize;
8891
update_handler_id_t _updateHandlerId;
8992

93+
// We assume we have a _filePath with format "/directory1/directory2/filename"
94+
// We create a directory for each missing parent
95+
void mkdirs() {
96+
String path(_filePath);
97+
int index = 0;
98+
while ((index = path.indexOf('/', index + 1)) != -1) {
99+
String segment = path.substring(0, index);
100+
if (!_fs->exists(segment)) {
101+
_fs->mkdir(segment);
102+
}
103+
}
104+
}
105+
90106
protected:
91107
// We assume the updater supplies sensible defaults if an empty object
92108
// is supplied, this virtual function allows that to be changed.

lib/framework/FactoryResetService.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ void FactoryResetService::factoryReset() {
2222
File root = fs->open(FS_CONFIG_DIRECTORY);
2323
File file;
2424
while (file = root.openNextFile()) {
25-
fs->remove(file.name());
25+
String path = file.path();
26+
file.close();
27+
fs->remove(path);
2628
}
2729
#elif defined(ESP8266)
2830
Dir configDirectory = fs->openDir(FS_CONFIG_DIRECTORY);

0 commit comments

Comments
 (0)