Skip to content

Commit 88e13a0

Browse files
committed
Fix #2750
1 parent 7dd537f commit 88e13a0

File tree

2 files changed

+30
-56
lines changed

2 files changed

+30
-56
lines changed

libraries/SPIFFS/src/SPIFFS.cpp

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,26 @@
1-
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2-
//
3-
// Licensed under the Apache License, Version 2.0 (the "License");
4-
// you may not use this file except in compliance with the License.
5-
// You may obtain a copy of the License at
6-
//
7-
// http://www.apache.org/licenses/LICENSE-2.0
8-
//
9-
// Unless required by applicable law or agreed to in writing, software
10-
// distributed under the License is distributed on an "AS IS" BASIS,
11-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
// See the License for the specific language governing permissions and
13-
// limitations under the License.
14-
15-
#include "vfs_api.h"
16-
171
extern "C" {
182
#include <sys/unistd.h>
193
#include <sys/stat.h>
204
#include <dirent.h>
215
#include "esp_spiffs.h"
226
}
7+
238
#include "SPIFFS.h"
249

2510
using namespace fs;
2611

27-
SPIFFSFS::SPIFFSFS(FSImplPtr impl)
28-
: FS(impl)
29-
{}
12+
SPIFFSImpl::SPIFFSImpl()
13+
{
14+
}
15+
16+
bool SPIFFSImpl::exists(const char* path) {
17+
File f = open(path, "r");
18+
return (f == true) && !f.isDirectory();
19+
}
20+
21+
SPIFFSFS::SPIFFSFS() : FS(FSImplPtr(new SPIFFSImpl())) {
22+
23+
}
3024

3125
bool SPIFFSFS::begin(bool formatOnFail, const char * basePath, uint8_t maxOpenFiles)
3226
{
@@ -68,8 +62,7 @@ void SPIFFSFS::end()
6862
}
6963
}
7064

71-
bool SPIFFSFS::format()
72-
{
65+
bool SPIFFSFS::format() {
7366
disableCore0WDT();
7467
esp_err_t err = esp_spiffs_format(NULL);
7568
enableCore0WDT();
@@ -80,34 +73,21 @@ bool SPIFFSFS::format()
8073
return true;
8174
}
8275

83-
size_t SPIFFSFS::totalBytes()
84-
{
76+
size_t SPIFFSFS::totalBytes() {
8577
size_t total,used;
8678
if(esp_spiffs_info(NULL, &total, &used)){
8779
return 0;
8880
}
8981
return total;
9082
}
9183

92-
size_t SPIFFSFS::usedBytes()
93-
{
84+
size_t SPIFFSFS::usedBytes() {
9485
size_t total,used;
9586
if(esp_spiffs_info(NULL, &total, &used)){
9687
return 0;
9788
}
9889
return used;
9990
}
10091

101-
bool SPIFFSFS::exists(const char* path)
102-
{
103-
File f = open(path, "r");
104-
return (f == true) && !f.isDirectory();
105-
}
106-
107-
bool SPIFFSFS::exists(const String& path)
108-
{
109-
return exists(path.c_str());
110-
}
111-
92+
SPIFFSFS SPIFFS;
11293

113-
SPIFFSFS SPIFFS = SPIFFSFS(FSImplPtr(new VFSImpl()));

libraries/SPIFFS/src/SPIFFS.h

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,33 @@
1-
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2-
//
3-
// Licensed under the Apache License, Version 2.0 (the "License");
4-
// you may not use this file except in compliance with the License.
5-
// You may obtain a copy of the License at
6-
//
7-
// http://www.apache.org/licenses/LICENSE-2.0
8-
//
9-
// Unless required by applicable law or agreed to in writing, software
10-
// distributed under the License is distributed on an "AS IS" BASIS,
11-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
// See the License for the specific language governing permissions and
13-
// limitations under the License.
14-
#ifndef _SPIFFS_H_
15-
#define _SPIFFS_H_
1+
#pragma once
162

173
#include "FS.h"
4+
#include "FSImpl.h"
5+
#include "vfs_api.h"
186

197
namespace fs
208
{
219

10+
class SPIFFSImpl : public VFSImpl
11+
{
12+
public:
13+
SPIFFSImpl();
14+
virtual ~SPIFFSImpl() { }
15+
virtual bool exists(const char* path);
16+
};
17+
2218
class SPIFFSFS : public FS
2319
{
2420
public:
25-
SPIFFSFS(FSImplPtr impl);
21+
SPIFFSFS();
2622
bool begin(bool formatOnFail=false, const char * basePath="/spiffs", uint8_t maxOpenFiles=10);
2723
bool format();
2824
size_t totalBytes();
2925
size_t usedBytes();
3026
void end();
31-
bool exists(const char* path);
32-
bool exists(const String& path);
3327
};
3428

3529
}
3630

3731
extern fs::SPIFFSFS SPIFFS;
3832

39-
#endif /* _SPIFFS_H_ */
33+

0 commit comments

Comments
 (0)