From 88e13a0df062ac15684a956c3e4d7560766f4fd3 Mon Sep 17 00:00:00 2001 From: Paul Andrews Date: Thu, 9 May 2019 08:51:44 -0400 Subject: [PATCH 1/4] Fix #2750 --- libraries/SPIFFS/src/SPIFFS.cpp | 54 +++++++++++---------------------- libraries/SPIFFS/src/SPIFFS.h | 32 ++++++++----------- 2 files changed, 30 insertions(+), 56 deletions(-) diff --git a/libraries/SPIFFS/src/SPIFFS.cpp b/libraries/SPIFFS/src/SPIFFS.cpp index 8dcded32955..1db3eed9433 100644 --- a/libraries/SPIFFS/src/SPIFFS.cpp +++ b/libraries/SPIFFS/src/SPIFFS.cpp @@ -1,32 +1,26 @@ -// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "vfs_api.h" - extern "C" { #include #include #include #include "esp_spiffs.h" } + #include "SPIFFS.h" using namespace fs; -SPIFFSFS::SPIFFSFS(FSImplPtr impl) - : FS(impl) -{} +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) { @@ -68,8 +62,7 @@ void SPIFFSFS::end() } } -bool SPIFFSFS::format() -{ +bool SPIFFSFS::format() { disableCore0WDT(); esp_err_t err = esp_spiffs_format(NULL); enableCore0WDT(); @@ -80,8 +73,7 @@ bool SPIFFSFS::format() return true; } -size_t SPIFFSFS::totalBytes() -{ +size_t SPIFFSFS::totalBytes() { size_t total,used; if(esp_spiffs_info(NULL, &total, &used)){ return 0; @@ -89,8 +81,7 @@ size_t SPIFFSFS::totalBytes() return total; } -size_t SPIFFSFS::usedBytes() -{ +size_t SPIFFSFS::usedBytes() { size_t total,used; if(esp_spiffs_info(NULL, &total, &used)){ return 0; @@ -98,16 +89,5 @@ size_t SPIFFSFS::usedBytes() return used; } -bool SPIFFSFS::exists(const char* path) -{ - File f = open(path, "r"); - return (f == true) && !f.isDirectory(); -} - -bool SPIFFSFS::exists(const String& path) -{ - return exists(path.c_str()); -} - +SPIFFSFS SPIFFS; -SPIFFSFS SPIFFS = SPIFFSFS(FSImplPtr(new VFSImpl())); diff --git a/libraries/SPIFFS/src/SPIFFS.h b/libraries/SPIFFS/src/SPIFFS.h index fe697b78fc8..476cd25be5a 100644 --- a/libraries/SPIFFS/src/SPIFFS.h +++ b/libraries/SPIFFS/src/SPIFFS.h @@ -1,39 +1,33 @@ -// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -#ifndef _SPIFFS_H_ -#define _SPIFFS_H_ +#pragma once #include "FS.h" +#include "FSImpl.h" +#include "vfs_api.h" namespace fs { +class SPIFFSImpl : public VFSImpl +{ +public: + SPIFFSImpl(); + virtual ~SPIFFSImpl() { } + virtual bool exists(const char* path); +}; + 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_ */ + From b28c423a47e2045ebb7e87173a20b43a7295ee18 Mon Sep 17 00:00:00 2001 From: Paul Andrews Date: Sat, 11 May 2019 10:04:32 -0400 Subject: [PATCH 2/4] Fixes for pull comments --- libraries/SPIFFS/src/SPIFFS.cpp | 29 ++++++++++++++++++++++++----- libraries/SPIFFS/src/SPIFFS.h | 21 +++++++++++++++++++-- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/libraries/SPIFFS/src/SPIFFS.cpp b/libraries/SPIFFS/src/SPIFFS.cpp index 1db3eed9433..14370f3f530 100644 --- a/libraries/SPIFFS/src/SPIFFS.cpp +++ b/libraries/SPIFFS/src/SPIFFS.cpp @@ -1,3 +1,17 @@ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + extern "C" { #include #include @@ -13,12 +27,14 @@ SPIFFSImpl::SPIFFSImpl() { } -bool SPIFFSImpl::exists(const char* path) { +bool SPIFFSImpl::exists(const char* path) +{ File f = open(path, "r"); return (f == true) && !f.isDirectory(); } -SPIFFSFS::SPIFFSFS() : FS(FSImplPtr(new SPIFFSImpl())) { +SPIFFSFS::SPIFFSFS() : FS(FSImplPtr(new SPIFFSImpl())) +{ } @@ -62,7 +78,8 @@ void SPIFFSFS::end() } } -bool SPIFFSFS::format() { +bool SPIFFSFS::format() +{ disableCore0WDT(); esp_err_t err = esp_spiffs_format(NULL); enableCore0WDT(); @@ -73,7 +90,8 @@ bool SPIFFSFS::format() { return true; } -size_t SPIFFSFS::totalBytes() { +size_t SPIFFSFS::totalBytes() +{ size_t total,used; if(esp_spiffs_info(NULL, &total, &used)){ return 0; @@ -81,7 +99,8 @@ size_t SPIFFSFS::totalBytes() { return total; } -size_t SPIFFSFS::usedBytes() { +size_t SPIFFSFS::usedBytes() +{ size_t total,used; if(esp_spiffs_info(NULL, &total, &used)){ return 0; diff --git a/libraries/SPIFFS/src/SPIFFS.h b/libraries/SPIFFS/src/SPIFFS.h index 476cd25be5a..8450e15d057 100644 --- a/libraries/SPIFFS/src/SPIFFS.h +++ b/libraries/SPIFFS/src/SPIFFS.h @@ -1,3 +1,19 @@ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#ifndef _SPIFFS_H_ +#define _SPIFFS_H_ + #pragma once #include "FS.h" @@ -10,7 +26,7 @@ namespace fs class SPIFFSImpl : public VFSImpl { public: - SPIFFSImpl(); + SPIFFSImpl(); virtual ~SPIFFSImpl() { } virtual bool exists(const char* path); }; @@ -18,7 +34,7 @@ class SPIFFSImpl : public VFSImpl class SPIFFSFS : public FS { public: - SPIFFSFS(); + SPIFFSFS(); bool begin(bool formatOnFail=false, const char * basePath="/spiffs", uint8_t maxOpenFiles=10); bool format(); size_t totalBytes(); @@ -31,3 +47,4 @@ class SPIFFSFS : public FS extern fs::SPIFFSFS SPIFFS; +#endif From 009e0bbd2c63341030352ffd610eaf68677f7307 Mon Sep 17 00:00:00 2001 From: Paul Andrews Date: Sun, 12 May 2019 18:43:34 -0400 Subject: [PATCH 3/4] latest modifications following comments from me-no-dev --- libraries/SPIFFS/src/SPIFFS.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libraries/SPIFFS/src/SPIFFS.h b/libraries/SPIFFS/src/SPIFFS.h index 8450e15d057..f9645950ae5 100644 --- a/libraries/SPIFFS/src/SPIFFS.h +++ b/libraries/SPIFFS/src/SPIFFS.h @@ -14,10 +14,6 @@ #ifndef _SPIFFS_H_ #define _SPIFFS_H_ -#pragma once - -#include "FS.h" -#include "FSImpl.h" #include "vfs_api.h" namespace fs From a67795940928f34a60c728c01d343482ac46c53f Mon Sep 17 00:00:00 2001 From: Paul Andrews Date: Mon, 13 May 2019 14:51:36 -0400 Subject: [PATCH 4/4] Move SPIFFSFSImpl to .cpp file --- libraries/SPIFFS/src/SPIFFS.cpp | 10 ++++++++++ libraries/SPIFFS/src/SPIFFS.h | 10 +--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/libraries/SPIFFS/src/SPIFFS.cpp b/libraries/SPIFFS/src/SPIFFS.cpp index 14370f3f530..db97fa2bf94 100644 --- a/libraries/SPIFFS/src/SPIFFS.cpp +++ b/libraries/SPIFFS/src/SPIFFS.cpp @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "vfs_api.h" + extern "C" { #include #include @@ -23,6 +25,14 @@ extern "C" { using namespace fs; +class SPIFFSImpl : public VFSImpl +{ +public: + SPIFFSImpl(); + virtual ~SPIFFSImpl() { } + virtual bool exists(const char* path); +}; + SPIFFSImpl::SPIFFSImpl() { } diff --git a/libraries/SPIFFS/src/SPIFFS.h b/libraries/SPIFFS/src/SPIFFS.h index f9645950ae5..7d35da0439a 100644 --- a/libraries/SPIFFS/src/SPIFFS.h +++ b/libraries/SPIFFS/src/SPIFFS.h @@ -14,19 +14,11 @@ #ifndef _SPIFFS_H_ #define _SPIFFS_H_ -#include "vfs_api.h" +#include "FS.h" namespace fs { -class SPIFFSImpl : public VFSImpl -{ -public: - SPIFFSImpl(); - virtual ~SPIFFSImpl() { } - virtual bool exists(const char* path); -}; - class SPIFFSFS : public FS { public: