From fd5a2f08f95429234179453a8d0c44fcb4770843 Mon Sep 17 00:00:00 2001 From: Paul Andrews Date: Mon, 13 May 2019 17:15:35 -0400 Subject: [PATCH] Fix #2750 (#2763) * Fix #2750 * Fixes for pull comments * latest modifications following comments from me-no-dev * Move SPIFFSFSImpl to .cpp file --- libraries/SPIFFS/src/SPIFFS.cpp | 39 ++++++++++++++++++++------------- libraries/SPIFFS/src/SPIFFS.h | 7 +++--- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/libraries/SPIFFS/src/SPIFFS.cpp b/libraries/SPIFFS/src/SPIFFS.cpp index 8dcded32..db97fa2b 100644 --- a/libraries/SPIFFS/src/SPIFFS.cpp +++ b/libraries/SPIFFS/src/SPIFFS.cpp @@ -20,13 +20,33 @@ extern "C" { #include #include "esp_spiffs.h" } + #include "SPIFFS.h" using namespace fs; -SPIFFSFS::SPIFFSFS(FSImplPtr impl) - : FS(impl) -{} +class SPIFFSImpl : public VFSImpl +{ +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) { @@ -98,16 +118,5 @@ size_t SPIFFSFS::usedBytes() return used; } -bool SPIFFSFS::exists(const char* path) -{ - File f = open(path, "r"); - return (f == true) && !f.isDirectory(); -} +SPIFFSFS SPIFFS; -bool SPIFFSFS::exists(const String& path) -{ - return exists(path.c_str()); -} - - -SPIFFSFS SPIFFS = SPIFFSFS(FSImplPtr(new VFSImpl())); diff --git a/libraries/SPIFFS/src/SPIFFS.h b/libraries/SPIFFS/src/SPIFFS.h index fe697b78..7d35da04 100644 --- a/libraries/SPIFFS/src/SPIFFS.h +++ b/libraries/SPIFFS/src/SPIFFS.h @@ -22,18 +22,17 @@ namespace fs class SPIFFSFS : public FS { public: - SPIFFSFS(FSImplPtr impl); + SPIFFSFS(); bool begin(bool formatOnFail=false, const char * basePath="/spiffs", uint8_t maxOpenFiles=10); bool format(); size_t totalBytes(); size_t usedBytes(); void end(); - bool exists(const char* path); - bool exists(const String& path); }; } extern fs::SPIFFSFS SPIFFS; -#endif /* _SPIFFS_H_ */ + +#endif