From 1dfe95f0a093f910dd076fbfa2441142639f8247 Mon Sep 17 00:00:00 2001 From: Luc <8822552+luc-github@users.noreply.github.com> Date: Mon, 25 May 2020 20:25:44 +0200 Subject: [PATCH] fix spiffs show . in directory when it should be ignored --- esp3d/src/include/version.h | 2 +- .../flash/spiffs_esp32_filesystem.cpp | 22 ++++++++++------ .../flash/spiffs_esp8266_filesystem.cpp | 26 +++++++++++++------ .../modules/http/handles/handle-command.cpp | 4 ++- 4 files changed, 36 insertions(+), 18 deletions(-) diff --git a/esp3d/src/include/version.h b/esp3d/src/include/version.h index bef791e8..7863489a 100644 --- a/esp3d/src/include/version.h +++ b/esp3d/src/include/version.h @@ -22,7 +22,7 @@ #define _VERSION_ESP3D_H //version and sources location -#define FW_VERSION "3.0.0.a39" +#define FW_VERSION "3.0.0.a40" #define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0" #endif //_VERSION_ESP3D_H diff --git a/esp3d/src/modules/filesystem/flash/spiffs_esp32_filesystem.cpp b/esp3d/src/modules/filesystem/flash/spiffs_esp32_filesystem.cpp index 1fdabe3d..50a2c853 100644 --- a/esp3d/src/modules/filesystem/flash/spiffs_esp32_filesystem.cpp +++ b/esp3d/src/modules/filesystem/flash/spiffs_esp32_filesystem.cpp @@ -272,7 +272,7 @@ ESP_File ESP_File::openNextFile() } File tmp = tFile_handle[_index].openNextFile(); while (tmp) { - //log_esp3d("tmp name :%s %s", tmp.name(), (tmp.isDirectory())?"isDir":"isFile"); + log_esp3d("tmp name :%s %s", tmp.name(), (tmp.isDirectory())?"isDir":"isFile"); ESP_File esptmp(&tmp, tmp.isDirectory()); esptmp.close(); String sub = esptmp.filename(); @@ -281,25 +281,31 @@ ESP_File ESP_File::openNextFile() if (pos!=-1) { //is subdir sub = sub.substring(0,pos); - //log_esp3d("file name:%s name: %s %s sub:%s root:%s", esptmp.filename(), esptmp.name(), (esptmp.isDirectory())?"isDir":"isFile", sub.c_str(), _filename.c_str()); + log_esp3d("file name:%s name: %s %s sub:%s root:%s", esptmp.filename(), esptmp.name(), (esptmp.isDirectory())?"isDir":"isFile", sub.c_str(), _filename.c_str()); String tag = "*" + sub + "*"; //test if already in directory list if (_dirlist.indexOf(tag) == -1) {//not in list so add it and return the info _dirlist+= tag; String fname = _filename.substring(0,_filename.length()-1) + sub + "/."; - //log_esp3d("Found dir name: %s filename:%s", sub.c_str(), fname.c_str()); - esptmp = ESP_File(sub.c_str(), fname.c_str()); - return esptmp; + log_esp3d("Found dir # name: %s filename:%s", sub.c_str(), fname.c_str()); + if (sub == ".") { + log_esp3d("Dir tag, ignore it"); + tmp = tFile_handle[_index].openNextFile(); + } else { + esptmp = ESP_File(sub.c_str(), fname.c_str()); + return esptmp; + } } else { //already in list so ignore it - //log_esp3d("Dir name: %s already in list", sub.c_str()); + log_esp3d("Dir name: %s already in list", sub.c_str()); tmp = tFile_handle[_index].openNextFile(); } } else { //is file - //log_esp3d("file name:%s name: %s %s sub:%s root:%s", esptmp.filename(), esptmp.name(), (esptmp.isDirectory())?"isDir":"isFile", sub.c_str(), _filename.c_str()); + log_esp3d("file name:%s name: %s %s sub:%s root:%s", esptmp.filename(), esptmp.name(), (esptmp.isDirectory())?"isDir":"isFile", sub.c_str(), _filename.c_str()); if (sub == ".") { - //log_esp3d("Dir tag, ignore it"); + log_esp3d("Dir tag, ignore it"); tmp = tFile_handle[_index].openNextFile(); } else { + log_esp3d("Found file # name: %s filename:%s", esptmp.filename(), esptmp.name()); return esptmp; } } diff --git a/esp3d/src/modules/filesystem/flash/spiffs_esp8266_filesystem.cpp b/esp3d/src/modules/filesystem/flash/spiffs_esp8266_filesystem.cpp index dfaa6037..ea5968c8 100644 --- a/esp3d/src/modules/filesystem/flash/spiffs_esp8266_filesystem.cpp +++ b/esp3d/src/modules/filesystem/flash/spiffs_esp8266_filesystem.cpp @@ -310,7 +310,7 @@ ESP_File ESP_File::openNextFile() return ESP_File(); } if(tDir_handle[_index].next()) { - //log_esp3d("Getting next file from %s", _filename.c_str()); + log_esp3d("Getting next file from %s", _filename.c_str()); File tmp = tDir_handle[_index].openFile("r"); while (tmp) { ESP_File esptmp(&tmp); @@ -321,17 +321,26 @@ ESP_File ESP_File::openNextFile() if (pos!=-1) { //is subdir sub = sub.substring(0,pos); - //log_esp3d("file name:%s name: %s %s sub:%s root:%s", esptmp.filename(), esptmp.name(), (esptmp.isDirectory())?"isDir":"isFile", sub.c_str(), _filename.c_str()); + log_esp3d("file name:%s name: %s %s sub:%s root:%s", esptmp.filename(), esptmp.name(), (esptmp.isDirectory())?"isDir":"isFile", sub.c_str(), _filename.c_str()); String tag = "*" + sub + "*"; //test if already in directory list if (_dirlist.indexOf(tag) == -1) {//not in list so add it and return the info _dirlist+= tag; String fname = _filename.substring(0,_filename.length()-1) + sub + "/."; - //log_esp3d("Found dir name: %s filename:%s", sub.c_str(), fname.c_str()); - esptmp = ESP_File(sub.c_str(), fname.c_str()); - return esptmp; + log_esp3d("Found dir # name: %s filename:%s", sub.c_str(), fname.c_str()); + if (sub == ".") { + log_esp3d("Dir tag, ignore it"); + if(!tDir_handle[_index].next()) { + return ESP_File(); + } else { + tmp = tDir_handle[_index].openFile("r"); + } + } else { + esptmp = ESP_File(sub.c_str(), fname.c_str()); + return esptmp; + } } else { //already in list so ignore it - //log_esp3d("Dir name: %s already in list", sub.c_str()); + log_esp3d("Dir name: %s already in list", sub.c_str()); if(!tDir_handle[_index].next()) { return ESP_File(); } else { @@ -339,15 +348,16 @@ ESP_File ESP_File::openNextFile() } } } else { //is file - //log_esp3d("file name:%s name: %s %s sub:%s root:%s", esptmp.filename(), esptmp.name(), (esptmp.isDirectory())?"isDir":"isFile", sub.c_str(), _filename.c_str()); + log_esp3d("file name:%s name: %s %s sub:%s root:%s", esptmp.filename(), esptmp.name(), (esptmp.isDirectory())?"isDir":"isFile", sub.c_str(), _filename.c_str()); if (sub == ".") { - //log_esp3d("Dir tag, ignore it"); + log_esp3d("Dir tag, ignore it"); if(!tDir_handle[_index].next()) { return ESP_File(); } else { tmp = tDir_handle[_index].openFile("r"); } } else { + log_esp3d("Found file # name: %s filename:%s", esptmp.filename(), esptmp.name()); return esptmp; } } diff --git a/esp3d/src/modules/http/handles/handle-command.cpp b/esp3d/src/modules/http/handles/handle-command.cpp index e44e6b80..dfd3ecd0 100644 --- a/esp3d/src/modules/http/handles/handle-command.cpp +++ b/esp3d/src/modules/http/handles/handle-command.cpp @@ -39,7 +39,9 @@ void HTTP_Server::handle_web_command () if (_webserver->hasArg ("cmd")) { cmd = _webserver->arg ("cmd"); ESP3DOutput output(_webserver); - if(!cmd.endsWith("\n")) cmd+="\n";//need to validate command + if(!cmd.endsWith("\n")) { + cmd+="\n"; //need to validate command + } esp3d_commands.process((uint8_t*)cmd.c_str(), cmd.length(), &output, auth_level); } else { _webserver->send (400, "text/plain", "Invalid command");