Filesystem fixes for LittleFS

raytac-diy
Thomas Göttgens 2022-09-21 16:47:10 +02:00
rodzic b38ae783b9
commit b5a8efa16b
4 zmienionych plików z 13 dodań i 13 usunięć

Wyświetl plik

@ -9,13 +9,13 @@ 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){
DEBUG_MSG("Failed to open file"); DEBUG_MSG("Failed to open source file %s\n", from);
return false; return false;
} }
File f2 = FSCom.open(to, FILE_O_WRITE); File f2 = FSCom.open(to, FILE_O_WRITE);
if (!f2) { if (!f2) {
DEBUG_MSG("Failed to open file"); DEBUG_MSG("Failed to open destination file %s\n", to);
return false; return false;
} }
@ -56,10 +56,10 @@ void listDir(const char * dirname, uint8_t levels)
while(file){ while(file){
if(file.isDirectory() && !String(file.name()).endsWith(".")) { if(file.isDirectory() && !String(file.name()).endsWith(".")) {
if(levels){ if(levels){
listDir(file.name(), levels -1); listDir(file.path(), levels -1);
} }
} else { } else {
DEBUG_MSG(" %s (%i Bytes)\n", file.name(), file.size()); DEBUG_MSG(" %s (%i Bytes)\n", file.path(), file.size());
} }
file.close(); file.close();
file = root.openNextFile(); file = root.openNextFile();
@ -94,16 +94,16 @@ void rmDir(const char * dirname)
strcat(dirpath,entry.name()); // append string two to the result. strcat(dirpath,entry.name()); // append string two to the result.
if(entry.isDirectory() && !String(entry.name()).endsWith(".")) { if(entry.isDirectory() && !String(entry.name()).endsWith(".")) {
entry.close(); entry.close();
// DEBUG_MSG("Descend DIR %s\n", dirpath); DEBUG_MSG("Descend DIR %s\n", dirpath);
rmDir(dirpath); rmDir(dirpath);
} else { } else {
entry.close(); entry.close();
// DEBUG_MSG("Remove FILE %s\n", entry.name()); DEBUG_MSG("Remove FILE %s\n", entry.name());
FSCom.remove(entry.name()); FSCom.remove(entry.name());
} }
} }
FSCom.rmdir(dirname); FSCom.rmdir(dirname);
// DEBUG_MSG("Remove DIR %s\n", dirname); DEBUG_MSG("Remove DIR %s\n", dirname);
file.close(); file.close();
#endif #endif
} }
@ -117,7 +117,7 @@ void fsInit()
assert(0); // FIXME - report failure to phone assert(0); // FIXME - report failure to phone
} }
DEBUG_MSG("Filesystem files:\n"); DEBUG_MSG("Filesystem files (%d/%d total Bytes):\n", FSCom.usedBytes(), FSCom.totalBytes());
listDir("/", 10); listDir("/", 10);
#endif #endif
} }

Wyświetl plik

@ -40,6 +40,7 @@ using namespace Adafruit_LittleFS_Namespace;
#endif #endif
void fsInit(); void fsInit();
bool copyFile(const char* from, const char* to);
bool renameFile(const char* pathFrom, const char* pathTo); bool renameFile(const char* pathFrom, const char* pathTo);
void listDir(const char * dirname, uint8_t levels); void listDir(const char * dirname, uint8_t levels);
void rmDir(const char * dirname); void rmDir(const char * dirname);

Wyświetl plik

@ -431,7 +431,6 @@ bool saveProto(const char *filename, size_t protoSize, size_t objSize, const pb_
} else { } else {
okay = true; okay = true;
} }
f.close(); f.close();
// brief window of risk here ;-) // brief window of risk here ;-)
@ -454,7 +453,7 @@ void NodeDB::saveChannelsToDisk()
#ifdef FSCom #ifdef FSCom
FSCom.mkdir("/prefs"); FSCom.mkdir("/prefs");
#endif #endif
saveProto(channelFileName, ChannelFile_size, sizeof(ChannelFile), ChannelFile_fields, &channelFile); saveProto(channelFileName, ChannelFile_size, sizeof(channelFile), ChannelFile_fields, &channelFile);
} }
} }
@ -484,7 +483,7 @@ void NodeDB::saveToDisk()
config.has_power = true; config.has_power = true;
config.has_network = true; config.has_network = true;
config.has_bluetooth = true; config.has_bluetooth = true;
saveProto(configFileName, LocalConfig_size, sizeof(LocalConfig), LocalConfig_fields, &config); saveProto(configFileName, LocalConfig_size, sizeof(config), LocalConfig_fields, &config);
moduleConfig.has_canned_message = true; moduleConfig.has_canned_message = true;
moduleConfig.has_external_notification = true; moduleConfig.has_external_notification = true;
@ -493,7 +492,7 @@ void NodeDB::saveToDisk()
moduleConfig.has_serial = true; moduleConfig.has_serial = true;
moduleConfig.has_store_forward = true; moduleConfig.has_store_forward = true;
moduleConfig.has_telemetry = true; moduleConfig.has_telemetry = true;
saveProto(moduleConfigFileName, LocalModuleConfig_size, sizeof(LocalModuleConfig), LocalModuleConfig_fields, &moduleConfig); saveProto(moduleConfigFileName, LocalModuleConfig_size, sizeof(moduleConfig), LocalModuleConfig_fields, &moduleConfig);
saveChannelsToDisk(); saveChannelsToDisk();
} else { } else {

Wyświetl plik

@ -411,7 +411,7 @@ bool CannedMessageModule::saveProtoForModule()
FS.mkdir("/prefs"); FS.mkdir("/prefs");
#endif #endif
okay &= saveProto(cannedMessagesConfigFile, CannedMessageModuleConfig_size, sizeof(CannedMessageModuleConfig), okay &= saveProto(cannedMessagesConfigFile, CannedMessageModuleConfig_size, sizeof(cannedMessageModuleConfig),
CannedMessageModuleConfig_fields, &cannedMessageModuleConfig); CannedMessageModuleConfig_fields, &cannedMessageModuleConfig);
return okay; return okay;