8000 Fix SPIFFS.openDir("") by igrr · Pull Request #2143 · esp8266/Arduino · GitHub
[go: up one dir, main page]

Skip to content

Fix SPIFFS.openDir("") #2143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 13, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update FS test cases
  • Loading branch information
igrr committed Jun 13, 2016
commit e8967b398dd8230ba46874d4ea3a6e2b3d2be22d
12 changes: 5 additions & 7 deletions cores/esp8266/spiffs_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
17 changes: 14 additions & 3 deletions tests/host/fs/test_fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
}
0