From 4c0535687f901d4c8dcab5b7022d77dbb0a1a84b Mon Sep 17 00:00:00 2001 From: Christian Baars Date: Thu, 6 Jul 2023 11:10:26 +0200 Subject: [PATCH] Accelerate path.listdir() (#18927) * Accelerate path.listdir() * restore old behavior, push filename only and not the full path to the list --- lib/libesp32/berry_tasmota/src/be_port.cpp | 26 ++++++++++------------ 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/libesp32/berry_tasmota/src/be_port.cpp b/lib/libesp32/berry_tasmota/src/be_port.cpp index 0cfac3573..647c94269 100644 --- a/lib/libesp32/berry_tasmota/src/be_port.cpp +++ b/lib/libesp32/berry_tasmota/src/be_port.cpp @@ -140,27 +140,25 @@ extern "C" { returnit = 1; case MPATH_ISDIR: case MPATH_MODIFIED: { - // listdir and isdir both need to open the file. + //isdir needs to open the file, listdir does not // we use be_fopen because it pre-pends with '/'. // without this TAS fails to find stuff at boot... File *dir = (File *)be_fopen(path, "r"); if (dir) { + String fpath; + String fname; switch (action){ case MPATH_LISTDIR: - // fill out the list object - dir->rewindDirectory(); - while (1) { - File entry = dir->openNextFile(); - if (!entry) { - break; - } - const char * fn = entry.name(); - if (strcmp(fn, ".") && strcmp(fn, "..")) { - be_pushstring(vm, fn); - be_data_push(vm, -2); - be_pop(vm, 1); - } + dir->seekDir(0); + fpath = dir->getNextFileName(); + while (fpath.length() != 0) { + fname = fpath.substring(fpath.lastIndexOf("/") + 1); + const char * fn = fname.c_str(); + be_pushstring(vm, fn); + be_data_push(vm, -2); + be_pop(vm, 1); + fpath = dir->getNextFileName(); } break; case MPATH_ISDIR: