* Fix #2750

* Fixes for pull comments

* latest modifications following comments from me-no-dev

* Move SPIFFSFSImpl to .cpp file
This commit is contained in:
Paul Andrews 2019-05-13 17:15:35 -04:00 committed by Me No Dev
parent e9389e3122
commit fd5a2f08f9
2 changed files with 27 additions and 19 deletions

View File

@ -20,13 +20,33 @@ extern "C" {
#include <dirent.h> #include <dirent.h>
#include "esp_spiffs.h" #include "esp_spiffs.h"
} }
#include "SPIFFS.h" #include "SPIFFS.h"
using namespace fs; using namespace fs;
SPIFFSFS::SPIFFSFS(FSImplPtr impl) class SPIFFSImpl : public VFSImpl
: FS(impl) {
{} public:
SPIFFSImpl();
virtual ~SPIFFSImpl() { }
virtual bool exists(const char* path);
};
SPIFFSImpl::SPIFFSImpl()
{
}
bool SPIFFSImpl::exists(const char* path)
{
File f = open(path, "r");
return (f == true) && !f.isDirectory();
}
SPIFFSFS::SPIFFSFS() : FS(FSImplPtr(new SPIFFSImpl()))
{
}
bool SPIFFSFS::begin(bool formatOnFail, const char * basePath, uint8_t maxOpenFiles) bool SPIFFSFS::begin(bool formatOnFail, const char * basePath, uint8_t maxOpenFiles)
{ {
@ -98,16 +118,5 @@ size_t SPIFFSFS::usedBytes()
return used; return used;
} }
bool SPIFFSFS::exists(const char* path) SPIFFSFS SPIFFS;
{
File f = open(path, "r");
return (f == true) && !f.isDirectory();
}
bool SPIFFSFS::exists(const String& path)
{
return exists(path.c_str());
}
SPIFFSFS SPIFFS = SPIFFSFS(FSImplPtr(new VFSImpl()));

View File

@ -22,18 +22,17 @@ namespace fs
class SPIFFSFS : public FS class SPIFFSFS : public FS
{ {
public: public:
SPIFFSFS(FSImplPtr impl); SPIFFSFS();
bool begin(bool formatOnFail=false, const char * basePath="/spiffs", uint8_t maxOpenFiles=10); bool begin(bool formatOnFail=false, const char * basePath="/spiffs", uint8_t maxOpenFiles=10);
bool format(); bool format();
size_t totalBytes(); size_t totalBytes();
size_t usedBytes(); size_t usedBytes();
void end(); void end();
bool exists(const char* path);
bool exists(const String& path);
}; };
} }
extern fs::SPIFFSFS SPIFFS; extern fs::SPIFFSFS SPIFFS;
#endif /* _SPIFFS_H_ */
#endif