From d16a71aa7c625b0bca7d1834f530824ef111afea Mon Sep 17 00:00:00 2001 From: seclorum Date: Fri, 25 Mar 2016 20:14:38 +0100 Subject: [PATCH 1/2] Update spiffs_api.cpp Fixes a bug where un-prefixed files are irretrievable with openDir(""). Described: https://github.com/esp8266/Arduino/issues/1818. --- cores/esp8266/spiffs_api.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cores/esp8266/spiffs_api.cpp b/cores/esp8266/spiffs_api.cpp index 5420174a94..f1c94791d4 100644 --- a/cores/esp8266/spiffs_api.cpp +++ b/cores/esp8266/spiffs_api.cpp @@ -63,12 +63,14 @@ bool SPIFFSImpl::exists(const char* path) return rc == SPIFFS_OK; } -DirImplPtr SPIFFSImpl::openDir(const char* path) -{ - if (!isSpiffsFilenameValid(path)) { - DEBUGV("SPIFFSImpl::openDir: invalid path=`%s` \r\n", path); - return DirImplPtr(); +DirImplPtr SPIFFSImpl::openDir(const char* path) { + if (strlen(path) > 0) { + if (!isSpiffsFilenameValid(path)) { + DEBUGV("SPIFFSImpl::openDir: invalid path=`%s` \r\n", path); + return DirImplPtr(); + } } + spiffs_DIR dir; spiffs_DIR* result = SPIFFS_opendir(&_fs, path, &dir); if (!result) { From e8967b398dd8230ba46874d4ea3a6e2b3d2be22d Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Mon, 13 Jun 2016 19:17:40 +0800 Subject: [PATCH 2/2] Update FS test cases --- cores/esp8266/spiffs_api.cpp | 12 +++++------- tests/host/fs/test_fs.cpp | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/cores/esp8266/spiffs_api.cpp b/cores/esp8266/spiffs_api.cpp index f1c94791d4..c8a05df060 100644 --- a/cores/esp8266/spiffs_api.cpp +++ b/cores/esp8266/spiffs_api.cpp @@ -63,14 +63,12 @@ bool SPIFFSImpl::exists(const char* path) return rc == SPIFFS_OK; } -DirImplPtr SPIFFSImpl::openDir(const char* path) { - if (strlen(path) > 0) { - if (!isSpiffsFilenameValid(path)) { - DEBUGV("SPIFFSImpl::openDir: invalid path=`%s` \r\n", path); - return DirImplPtr(); - } +DirImplPtr SPIFFSImpl::openDir(const char* path) +{ + if (strlen(path) > 0 && !isSpiffsFilenameValid(path)) { + DEBUGV("SPIFFSImpl::openDir: invalid path=`%s` \r\n", path); + return DirImplPtr(); } - spiffs_DIR dir; spiffs_DIR* result = SPIFFS_opendir(&_fs, path, &dir); if (!result) { diff --git a/tests/host/fs/test_fs.cpp b/tests/host/fs/test_fs.cpp index ad5e9fd650..6e14af84f2 100644 --- a/tests/host/fs/test_fs.cpp +++ b/tests/host/fs/test_fs.cpp @@ -160,11 +160,10 @@ TEST_CASE("File names which are too long are rejected", "[fs]") REQUIRE(SPIFFS.open(longName_31, "w")); REQUIRE(SPIFFS.open(longName_31, "r")); REQUIRE(SPIFFS.exists(longName_31)); - auto files = listDir(""); - REQUIRE(files.empty()); } -TEST_CASE("#1685 Duplicate files", "[fs][bugreport]") { +TEST_CASE("#1685 Duplicate files", "[fs][bugreport]") +{ SPIFFS_MOCK_DECLARE(64, 8, 512); REQUIRE(SPIFFS.begin()); createFile("/config", "some text"); @@ -173,3 +172,15 @@ TEST_CASE("#1685 Duplicate files", "[fs][bugreport]") { createFile("/data", "more text"); listDir("/"); } + +TEST_CASE("#1819 Can list all files with openDir(\"\")", "[fs][bugreport]") +{ + SPIFFS_MOCK_DECLARE(64, 8, 512); + REQUIRE(SPIFFS.begin()); + createFile("/file1", "some text"); + createFile("/file2", "other text"); + createFile("file3", "more text"); + createFile("sorta-dir/file4", "\n"); + auto files = listDir(""); + REQUIRE(files.size() == 4); +}