Remove file first

This commit is contained in:
Ben Meadors 2025-01-23 05:39:09 -06:00
parent 590b8e7018
commit bdc9c7ffd5
2 changed files with 4 additions and 5 deletions

View File

@ -3,14 +3,13 @@
#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, bool removeFirst) static File openFile(const char *filename, bool fullAtomic)
{ {
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
lfs_assert_failed = false; lfs_assert_failed = false;
if (removeFirst) FSCom.remove(filename);
FSCom.remove(filename);
return FSCom.open(filename, FILE_O_WRITE); return FSCom.open(filename, FILE_O_WRITE);
#endif #endif
if (!fullAtomic) if (!fullAtomic)
@ -24,7 +23,7 @@ static File openFile(const char *filename, bool fullAtomic, bool removeFirst)
} }
SafeFile::SafeFile(const char *_filename, bool fullAtomic, bool removeFirst) SafeFile::SafeFile(const char *_filename, bool fullAtomic, bool removeFirst)
: filename(_filename), f(openFile(_filename, fullAtomic, removeFirst)), fullAtomic(fullAtomic) : filename(_filename), f(openFile(_filename, fullAtomic)), fullAtomic(fullAtomic)
{ {
} }

View File

@ -25,7 +25,7 @@
class SafeFile : public Print class SafeFile : public Print
{ {
public: public:
explicit SafeFile(char const *filepath, bool fullAtomic = false, bool removeFirst = false); explicit SafeFile(char const *filepath, bool fullAtomic = 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);