sforkowany z mirror/meshtastic-firmware
Work around bug in littlefs rename() for now. After upstream change to version 2.5 this can be reverted.
rodzic
7b438cd16b
commit
295dca8415
|
@ -1,6 +1,46 @@
|
|||
#include "configuration.h"
|
||||
#include "FSCommon.h"
|
||||
|
||||
|
||||
bool copyFile(const char* from, const char* to)
|
||||
{
|
||||
#ifdef FSCom
|
||||
unsigned char cbuffer[16];
|
||||
|
||||
File f1 = FSCom.open(from, FILE_O_READ);
|
||||
if (!f1){
|
||||
DEBUG_MSG("Failed to open file");
|
||||
return false;
|
||||
}
|
||||
|
||||
File f2 = FSCom.open(to, FILE_O_WRITE);
|
||||
if (!f2) {
|
||||
DEBUG_MSG("Failed to open file");
|
||||
return false;
|
||||
}
|
||||
|
||||
while (f1.available() > 0) {
|
||||
byte i = f1.read(cbuffer, 16);
|
||||
f2.write(cbuffer, i);
|
||||
}
|
||||
|
||||
f2.close();
|
||||
f1.close();
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool renameFile(const char* pathFrom, const char* pathTo)
|
||||
{
|
||||
#ifdef FSCom
|
||||
if (copyFile(pathFrom, pathTo) & FSCom.remove(pathFrom) ) {
|
||||
return true;
|
||||
} else{
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void listDir(const char * dirname, uint8_t levels)
|
||||
{
|
||||
#ifdef FSCom
|
||||
|
|
|
@ -31,5 +31,6 @@ using namespace Adafruit_LittleFS_Namespace;
|
|||
#endif
|
||||
|
||||
void fsInit();
|
||||
bool renameFile(const char* pathFrom, const char* pathTo);
|
||||
void listDir(const char * dirname, uint8_t levels);
|
||||
void rmDir(const char * dirname);
|
||||
|
|
|
@ -414,7 +414,7 @@ bool saveProto(const char *filename, size_t protoSize, size_t objSize, const pb_
|
|||
// brief window of risk here ;-)
|
||||
if (FSCom.exists(filename) && !FSCom.remove(filename))
|
||||
DEBUG_MSG("Warning: Can't remove old pref file\n");
|
||||
if (!FSCom.rename(filenameTmp.c_str(), filename))
|
||||
if (!renameFile(filenameTmp.c_str(), filename))
|
||||
DEBUG_MSG("Error: can't rename new pref file\n");
|
||||
} else {
|
||||
DEBUG_MSG("Can't write prefs\n");
|
||||
|
|
Ładowanie…
Reference in New Issue