Open file for write should truncate file to match SD.h implementation

This commit is contained in:
Dave Allie
2025-12-30 15:59:38 +11:00
parent 0d269feed2
commit bf642c496d

View File

@@ -208,7 +208,7 @@ bool SDCardManager::openFileForRead(const char* moduleName, const char* path, Fs
return false; return false;
} }
file = sd.open(path, FILE_READ); file = sd.open(path, O_RDONLY);
if (!file) { if (!file) {
Serial.printf("[%lu] [%s] Failed to open file for reading: %s\n", millis(), moduleName, path); Serial.printf("[%lu] [%s] Failed to open file for reading: %s\n", millis(), moduleName, path);
return false; return false;
@@ -225,7 +225,7 @@ bool SDCardManager::openFileForRead(const char* moduleName, const String& path,
} }
bool SDCardManager::openFileForWrite(const char* moduleName, const char* path, FsFile& file) { bool SDCardManager::openFileForWrite(const char* moduleName, const char* path, FsFile& file) {
file = sd.open(path, FILE_WRITE); file = sd.open(path, O_RDWR | O_CREAT | O_TRUNC);
if (!file) { if (!file) {
Serial.printf("[%lu] [%s] Failed to open file for writing: %s\n", millis(), moduleName, path); Serial.printf("[%lu] [%s] Failed to open file for writing: %s\n", millis(), moduleName, path);
return false; return false;