File tree 3 files changed +24
-1
lines changed
3 files changed +24
-1
lines changed Original file line number Diff line number Diff line change
1
+ #ifndef ESPFS_H_
2
+ #define ESPFS_H_
3
+
1
4
#include <LittleFS.h>
2
5
#define ESPFS LittleFS
6
+
7
+ #endif
Original file line number Diff line number Diff line change @@ -51,6 +51,9 @@ class FSPersistence {
51
51
JsonObject jsonObject = jsonDocument.to <JsonObject>();
52
52
_statefulService->read (jsonObject, _stateReader);
53
53
54
+ // make directories if required
55
+ mkdirs ();
56
+
54
57
// serialize it to filesystem
55
58
File settingsFile = _fs->open (_filePath, " w" );
56
59
@@ -87,6 +90,19 @@ class FSPersistence {
87
90
size_t _bufferSize;
88
91
update_handler_id_t _updateHandlerId;
89
92
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
+
90
106
protected:
91
107
// We assume the updater supplies sensible defaults if an empty object
92
108
// is supplied, this virtual function allows that to be changed.
Original file line number Diff line number Diff line change @@ -22,7 +22,9 @@ void FactoryResetService::factoryReset() {
22
22
File root = fs->open (FS_CONFIG_DIRECTORY);
23
23
File file;
24
24
while (file = root.openNextFile ()) {
25
- fs->remove (file.name ());
25
+ String path = file.path ();
26
+ file.close ();
27
+ fs->remove (path);
26
28
}
27
29
#elif defined(ESP8266)
28
30
Dir configDirectory = fs->openDir (FS_CONFIG_DIRECTORY);
You can’t perform that action at this time.
0 commit comments