mirror of
https://github.com/meshtastic/firmware.git
synced 2025-09-30 04:50:58 +00:00
Remove prefs first
This commit is contained in:
parent
8e8b22edb0
commit
590b8e7018
@ -3,14 +3,15 @@
|
|||||||
#ifdef FSCom
|
#ifdef FSCom
|
||||||
|
|
||||||
// Only way to work on both esp32 and nrf52
|
// Only way to work on both esp32 and nrf52
|
||||||
static File openFile(const char *filename, bool fullAtomic)
|
static File openFile(const char *filename, bool fullAtomic, bool removeFirst)
|
||||||
{
|
{
|
||||||
concurrency::LockGuard g(spiLock);
|
concurrency::LockGuard g(spiLock);
|
||||||
LOG_DEBUG("Opening %s, fullAtomic=%d", filename, fullAtomic);
|
LOG_DEBUG("Opening %s, fullAtomic=%d", filename, fullAtomic);
|
||||||
#ifdef ARCH_NRF52
|
#ifdef ARCH_NRF52
|
||||||
File file = FSCom.open(filename, FILE_O_WRITE);
|
lfs_assert_failed = false;
|
||||||
file.seek(0);
|
if (removeFirst)
|
||||||
return file;
|
FSCom.remove(filename);
|
||||||
|
return FSCom.open(filename, FILE_O_WRITE);
|
||||||
#endif
|
#endif
|
||||||
if (!fullAtomic)
|
if (!fullAtomic)
|
||||||
FSCom.remove(filename); // Nuke the old file to make space (ignore if it !exists)
|
FSCom.remove(filename); // Nuke the old file to make space (ignore if it !exists)
|
||||||
@ -22,8 +23,8 @@ static File openFile(const char *filename, bool fullAtomic)
|
|||||||
return FSCom.open(filenameTmp.c_str(), FILE_O_WRITE);
|
return FSCom.open(filenameTmp.c_str(), FILE_O_WRITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
SafeFile::SafeFile(const char *_filename, bool fullAtomic)
|
SafeFile::SafeFile(const char *_filename, bool fullAtomic, bool removeFirst)
|
||||||
: filename(_filename), f(openFile(_filename, fullAtomic)), fullAtomic(fullAtomic)
|
: filename(_filename), f(openFile(_filename, fullAtomic, removeFirst)), fullAtomic(fullAtomic)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
class SafeFile : public Print
|
class SafeFile : public Print
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit SafeFile(char const *filepath, bool fullAtomic = false);
|
explicit SafeFile(char const *filepath, bool fullAtomic = false, bool removeFirst = false);
|
||||||
|
|
||||||
virtual size_t write(uint8_t);
|
virtual size_t write(uint8_t);
|
||||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||||
|
@ -1104,7 +1104,15 @@ bool NodeDB::saveProto(const char *filename, size_t protoSize, const pb_msgdesc_
|
|||||||
{
|
{
|
||||||
bool okay = false;
|
bool okay = false;
|
||||||
#ifdef FSCom
|
#ifdef FSCom
|
||||||
auto f = SafeFile(filename, fullAtomic);
|
bool removeFirst = false;
|
||||||
|
#ifdef ARCH_NRF52
|
||||||
|
// On nrf52 we have to fully remove the device state file before writing it,
|
||||||
|
// because the filesystem seems to just append to the file otherwise.
|
||||||
|
if (filename == prefFileName) {
|
||||||
|
removeFirst = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
auto f = SafeFile(filename, fullAtomic, removeFirst);
|
||||||
|
|
||||||
LOG_INFO("Save %s", filename);
|
LOG_INFO("Save %s", filename);
|
||||||
pb_ostream_t stream = {&writecb, static_cast<Print *>(&f), protoSize};
|
pb_ostream_t stream = {&writecb, static_cast<Print *>(&f), protoSize};
|
||||||
|
Loading…
Reference in New Issue
Block a user