diff --git a/cores/esp8266/FS.cpp b/cores/esp8266/FS.cpp index 4951b798b..9461d9fdd 100644 --- a/cores/esp8266/FS.cpp +++ b/cores/esp8266/FS.cpp @@ -262,6 +262,13 @@ void FS::end() { } } +bool FS::gc() { + if (!_impl) { + return false; + } + return _impl->gc(); +} + bool FS::format() { if (!_impl) { return false; diff --git a/cores/esp8266/FS.h b/cores/esp8266/FS.h index d9c43ef3b..2cc6acd12 100644 --- a/cores/esp8266/FS.h +++ b/cores/esp8266/FS.h @@ -107,7 +107,7 @@ public: File openNextFile(); String readString() override; - + protected: FileImplPtr _p; @@ -181,7 +181,7 @@ public: bool begin(); void end(); - + bool format(); bool info(FSInfo& info); @@ -206,6 +206,8 @@ public: bool rmdir(const char* path); bool rmdir(const String& path); + bool gc(); + protected: FSImplPtr _impl; }; diff --git a/cores/esp8266/FSImpl.h b/cores/esp8266/FSImpl.h index 4c0ab2ccf..a668f2887 100644 --- a/cores/esp8266/FSImpl.h +++ b/cores/esp8266/FSImpl.h @@ -82,6 +82,7 @@ public: virtual bool remove(const char* path) = 0; virtual bool mkdir(const char* path) = 0; virtual bool rmdir(const char* path) = 0; + virtual bool gc() { return true; } // May not be implemented in all file systems. }; } // namespace fs diff --git a/cores/esp8266/spiffs_api.h b/cores/esp8266/spiffs_api.h index a0136849e..95600a22a 100644 --- a/cores/esp8266/spiffs_api.h +++ b/cores/esp8266/spiffs_api.h @@ -208,6 +208,11 @@ public: return true; } + bool gc() override + { + return SPIFFS_gc_quick( &_fs, 0 ) == SPIFFS_OK; + } + protected: friend class SPIFFSFileImpl; friend class SPIFFSDirImpl; @@ -290,7 +295,7 @@ protected: (void) report; (void) arg1; (void) arg2; - + // TODO: spiffs doesn't pass any context pointer along with _check_cb, // so we can't do anything useful here other than perhaps // feeding the watchdog