Skip to content

Commit b9dfe01

Browse files
authored
Fix SPIFFS.openDir("") (#2143)
* Update spiffs_api.cpp Fixes a bug where un-prefixed files are irretrievable with openDir(""). Described: #1818. * Update FS test cases
1 parent 9172033 commit b9dfe01

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

cores/esp8266/spiffs_api.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ bool SPIFFSImpl::exists(const char* path)
6363
return rc == SPIFFS_OK;
6464
}
6565

66-
DirImplPtr SPIFFSImpl::openDir(const char* path)
66+
DirImplPtr SPIFFSImpl::openDir(const char* path)
6767
{
68-
if (!isSpiffsFilenameValid(path)) {
68+
if (strlen(path) > 0 && !isSpiffsFilenameValid(path)) {
6969
DEBUGV("SPIFFSImpl::openDir: invalid path=`%s` \r\n", path);
7070
return DirImplPtr();
7171
}

tests/host/fs/test_fs.cpp

+14-3
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,10 @@ TEST_CASE("File names which are too long are rejected", "[fs]")
160160
REQUIRE(SPIFFS.open(longName_31, "w"));
161161
REQUIRE(SPIFFS.open(longName_31, "r"));
162162
REQUIRE(SPIFFS.exists(longName_31));
163-
auto files = listDir("");
164-
REQUIRE(files.empty());
165163
}
166164

167-
TEST_CASE("#1685 Duplicate files", "[fs][bugreport]") {
165+
TEST_CASE("#1685 Duplicate files", "[fs][bugreport]")
166+
{
168167
SPIFFS_MOCK_DECLARE(64, 8, 512);
169168
REQUIRE(SPIFFS.begin());
170169
createFile("/config", "some text");
@@ -173,3 +172,15 @@ TEST_CASE("#1685 Duplicate files", "[fs][bugreport]") {
173172
createFile("/data", "more text");
174173
listDir("/");
175174
}
175+
176+
TEST_CASE("#1819 Can list all files with openDir(\"\")", "[fs][bugreport]")
177+
{
178+
SPIFFS_MOCK_DECLARE(64, 8, 512);
179+
REQUIRE(SPIFFS.begin());
180+
createFile("/file1", "some text");
181+
createFile("/file2", "other text");
182+
createFile("file3", "more text");
183+
createFile("sorta-dir/file4", "\n");
184+
auto files = listDir("");
185+
REQUIRE(files.size() == 4);
186+
}

0 commit comments

Comments
 (0)