From 125f76d9845f736099d08727171cbb3a4a2fa409 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Wed, 15 Jun 2022 17:52:37 +0200 Subject: [PATCH] Don't use rmdir_r but roll our own version. --- src/FSCommon.cpp | 28 ++++++++++++++++++++++++++++ src/FSCommon.h | 4 +++- src/mesh/NodeDB.cpp | 2 +- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/FSCommon.cpp b/src/FSCommon.cpp index 3a2f8a92e..5293c4015 100644 --- a/src/FSCommon.cpp +++ b/src/FSCommon.cpp @@ -28,6 +28,34 @@ void listDir(const char * dirname, uint8_t levels) #endif } +void rmDir(const char * dirname) +#ifdef FSCom +{ + File root = FSCom.open(dirname); + if(!root){ + return; + } + if(!root.isDirectory()){ + return; + } + + File file = root.openNextFile(); + while(file){ + if(file.isDirectory() && !String(file.name()).endsWith(".")) { + file.close(); + rmDir(file.name()); + FSCom.rmdir(file.name()); + } else { + file.close(); + FSCom.remove(file.name()); + } + file.close(); + file = root.openNextFile(); + } + file.close(); +#endif +} + void fsInit() { #ifdef FSCom diff --git a/src/FSCommon.h b/src/FSCommon.h index be515b946..26d4f9f88 100644 --- a/src/FSCommon.h +++ b/src/FSCommon.h @@ -26,4 +26,6 @@ using namespace Adafruit_LittleFS_Namespace; #endif -void fsInit(); \ No newline at end of file +void fsInit(); +void listDir(const char * dirname, uint8_t levels); +void rmDir(const char * dirname); diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index c4ab8cad0..f70ffa1dd 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -91,7 +91,7 @@ bool NodeDB::resetRadioConfig() if (config.device.factory_reset) { DEBUG_MSG("Performing factory reset!\n"); // first, remove the "/prefs" (this removes most prefs) - FSCom.rmdir_r("/prefs"); + rmDir("/prefs"); // second, install default state (this will deal with the duplicate mac address issue) installDefaultDeviceState(); // third, write to disk