Compare commits

...

2 Commits

Author SHA1 Message Date
GUVWAF
12f0df49a1 More missing unlocks 2024-12-18 21:03:20 +01:00
GUVWAF
390b396c61 Add missing unlock 2024-12-18 20:50:05 +01:00
3 changed files with 11 additions and 3 deletions

View File

@ -101,12 +101,14 @@ bool copyFile(const char *from, const char *to)
File f1 = FSCom.open(from, FILE_O_READ); File f1 = FSCom.open(from, FILE_O_READ);
if (!f1) { if (!f1) {
LOG_ERROR("Failed to open source file %s", from); LOG_ERROR("Failed to open source file %s", from);
spiLock->unlock();
return false; return false;
} }
File f2 = FSCom.open(to, FILE_O_WRITE); File f2 = FSCom.open(to, FILE_O_WRITE);
if (!f2) { if (!f2) {
LOG_ERROR("Failed to open destination file %s", to); LOG_ERROR("Failed to open destination file %s", to);
spiLock->unlock();
return false; return false;
} }
@ -145,8 +147,9 @@ bool renameFile(const char *pathFrom, const char *pathTo)
// take SPI Lock // take SPI Lock
spiLock->lock(); spiLock->lock();
// rename was fixed for ESP32 IDF LittleFS in April // rename was fixed for ESP32 IDF LittleFS in April
return FSCom.rename(pathFrom, pathTo); bool result = FSCom.rename(pathFrom, pathTo);
spiLock->unlock(); spiLock->unlock();
return result;
#else #else
// copyFile does its own locking. // copyFile does its own locking.
if (copyFile(pathFrom, pathTo) && FSCom.remove(pathFrom)) { if (copyFile(pathFrom, pathTo) && FSCom.remove(pathFrom)) {

View File

@ -43,6 +43,7 @@ bool readcb(pb_istream_t *stream, uint8_t *buf, size_t count)
if (buf == NULL) { if (buf == NULL) {
while (count-- && file->read() != EOF) while (count-- && file->read() != EOF)
; ;
spiLock->unlock();
return count == 0; return count == 0;
} }
@ -75,4 +76,4 @@ bool is_in_helper(uint32_t n, const uint32_t *array, pb_size_t count)
return true; return true;
return false; return false;
} }

View File

@ -213,11 +213,13 @@ bool RangeTestModuleRadio::appendFile(const meshtastic_MeshPacket &mp)
spiLock->lock(); spiLock->lock();
if (!FSBegin()) { if (!FSBegin()) {
LOG_DEBUG("An Error has occurred while mounting the filesystem"); LOG_DEBUG("An Error has occurred while mounting the filesystem");
spiLock->unlock();
return 0; return 0;
} }
if (FSCom.totalBytes() - FSCom.usedBytes() < 51200) { if (FSCom.totalBytes() - FSCom.usedBytes() < 51200) {
LOG_DEBUG("Filesystem doesn't have enough free space. Aborting write"); LOG_DEBUG("Filesystem doesn't have enough free space. Aborting write");
spiLock->unlock();
return 0; return 0;
} }
@ -230,6 +232,7 @@ bool RangeTestModuleRadio::appendFile(const meshtastic_MeshPacket &mp)
if (!fileToWrite) { if (!fileToWrite) {
LOG_ERROR("There was an error opening the file for writing"); LOG_ERROR("There was an error opening the file for writing");
spiLock->unlock();
return 0; return 0;
} }
@ -249,6 +252,7 @@ bool RangeTestModuleRadio::appendFile(const meshtastic_MeshPacket &mp)
if (!fileToAppend) { if (!fileToAppend) {
LOG_ERROR("There was an error opening the file for appending"); LOG_ERROR("There was an error opening the file for appending");
spiLock->unlock();
return 0; return 0;
} }
@ -295,4 +299,4 @@ bool RangeTestModuleRadio::appendFile(const meshtastic_MeshPacket &mp)
#endif #endif
return 1; return 1;
} }