diff --git a/src/FSCommon.cpp b/src/FSCommon.cpp index 9ffd183f4..a5c17c2a8 100644 --- a/src/FSCommon.cpp +++ b/src/FSCommon.cpp @@ -101,12 +101,14 @@ bool copyFile(const char *from, const char *to) File f1 = FSCom.open(from, FILE_O_READ); if (!f1) { LOG_ERROR("Failed to open source file %s", from); + spiLock->unlock(); return false; } File f2 = FSCom.open(to, FILE_O_WRITE); if (!f2) { LOG_ERROR("Failed to open destination file %s", to); + spiLock->unlock(); return false; } @@ -145,8 +147,9 @@ bool renameFile(const char *pathFrom, const char *pathTo) // take SPI Lock spiLock->lock(); // rename was fixed for ESP32 IDF LittleFS in April - return FSCom.rename(pathFrom, pathTo); + bool result = FSCom.rename(pathFrom, pathTo); spiLock->unlock(); + return result; #else // copyFile does its own locking. if (copyFile(pathFrom, pathTo) && FSCom.remove(pathFrom)) { diff --git a/src/modules/RangeTestModule.cpp b/src/modules/RangeTestModule.cpp index 677cf30f7..e3c8a2e2f 100644 --- a/src/modules/RangeTestModule.cpp +++ b/src/modules/RangeTestModule.cpp @@ -213,11 +213,13 @@ bool RangeTestModuleRadio::appendFile(const meshtastic_MeshPacket &mp) spiLock->lock(); if (!FSBegin()) { LOG_DEBUG("An Error has occurred while mounting the filesystem"); + spiLock->unlock(); return 0; } if (FSCom.totalBytes() - FSCom.usedBytes() < 51200) { LOG_DEBUG("Filesystem doesn't have enough free space. Aborting write"); + spiLock->unlock(); return 0; } @@ -230,6 +232,7 @@ bool RangeTestModuleRadio::appendFile(const meshtastic_MeshPacket &mp) if (!fileToWrite) { LOG_ERROR("There was an error opening the file for writing"); + spiLock->unlock(); return 0; } @@ -249,6 +252,7 @@ bool RangeTestModuleRadio::appendFile(const meshtastic_MeshPacket &mp) if (!fileToAppend) { LOG_ERROR("There was an error opening the file for appending"); + spiLock->unlock(); return 0; } @@ -295,4 +299,4 @@ bool RangeTestModuleRadio::appendFile(const meshtastic_MeshPacket &mp) #endif return 1; -} +} \ No newline at end of file