Skip to content

Commit

Permalink
Upgrade e32 4.3.0 (rjwats#303)
Browse files Browse the repository at this point in the history
* fix system reset service for esp32
* make missing directories when saving files
  • Loading branch information
rjwats authored May 21, 2022
1 parent 004659b commit b9b9c1b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/framework/ESPFS.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
#ifndef ESPFS_H_
#define ESPFS_H_

#include <LittleFS.h>
#define ESPFS LittleFS

#endif
16 changes: 16 additions & 0 deletions lib/framework/FSPersistence.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class FSPersistence {
JsonObject jsonObject = jsonDocument.to<JsonObject>();
_statefulService->read(jsonObject, _stateReader);

// make directories if required
mkdirs();

// serialize it to filesystem
File settingsFile = _fs->open(_filePath, "w");

Expand Down Expand Up @@ -87,6 +90,19 @@ class FSPersistence {
size_t _bufferSize;
update_handler_id_t _updateHandlerId;

// We assume we have a _filePath with format "/directory1/directory2/filename"
// We create a directory for each missing parent
void mkdirs() {
String path(_filePath);
int index = 0;
while ((index = path.indexOf('/', index + 1)) != -1) {
String segment = path.substring(0, index);
if (!_fs->exists(segment)) {
_fs->mkdir(segment);
}
}
}

protected:
// We assume the updater supplies sensible defaults if an empty object
// is supplied, this virtual function allows that to be changed.
Expand Down
4 changes: 3 additions & 1 deletion lib/framework/FactoryResetService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ void FactoryResetService::factoryReset() {
File root = fs->open(FS_CONFIG_DIRECTORY);
File file;
while (file = root.openNextFile()) {
fs->remove(file.name());
String path = file.path();
file.close();
fs->remove(path);
}
#elif defined(ESP8266)
Dir configDirectory = fs->openDir(FS_CONFIG_DIRECTORY);
Expand Down

0 comments on commit b9b9c1b

Please sign in to comment.