Skip to content

Commit f950d53

Browse files
TD-erearlephilhower
authored andcommitted
Make SPIFFS garbage collection publicly available (#5944)
Original issue: #2870
1 parent 9712170 commit f950d53

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

cores/esp8266/FS.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,13 @@ void FS::end() {
262262
}
263263
}
264264

265+
bool FS::gc() {
266+
if (!_impl) {
267+
return false;
268+
}
269+
return _impl->gc();
270+
}
271+
265272
bool FS::format() {
266273
if (!_impl) {
267274
return false;

cores/esp8266/FS.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class File : public Stream
107107
File openNextFile();
108108

109109
String readString() override;
110-
110+
111111
protected:
112112
FileImplPtr _p;
113113

@@ -181,7 +181,7 @@ class FS
181181

182182
bool begin();
183183
void end();
184-
184+
185185
bool format();
186186
bool info(FSInfo& info);
187187

@@ -206,6 +206,8 @@ class FS
206206
bool rmdir(const char* path);
207207
bool rmdir(const String& path);
208208

209+
bool gc();
210+
209211
protected:
210212
FSImplPtr _impl;
211213
};

cores/esp8266/FSImpl.h

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class FSImpl {
8282
virtual bool remove(const char* path) = 0;
8383
virtual bool mkdir(const char* path) = 0;
8484
virtual bool rmdir(const char* path) = 0;
85+
virtual bool gc() { return true; } // May not be implemented in all file systems.
8586
};
8687

8788
} // namespace fs

cores/esp8266/spiffs_api.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ class SPIFFSImpl : public FSImpl
208208
return true;
209209
}
210210

211+
bool gc() override
212+
{
213+
return SPIFFS_gc_quick( &_fs, 0 ) == SPIFFS_OK;
214+
}
215+
211216
protected:
212217
friend class SPIFFSFileImpl;
213218
friend class SPIFFSDirImpl;
@@ -290,7 +295,7 @@ class SPIFFSImpl : public FSImpl
290295
(void) report;
291296
(void) arg1;
292297
(void) arg2;
293-
298+
294299
// TODO: spiffs doesn't pass any context pointer along with _check_cb,
295300
// so we can't do anything useful here other than perhaps
296301
// feeding the watchdog

0 commit comments

Comments
 (0)