Abort file loading if saving the file to the sd card fails

This commit is contained in:
Maschell 2022-08-25 15:38:12 +02:00
parent 7d7b04f3ea
commit 2d87a6e982
3 changed files with 8 additions and 4 deletions

View File

@ -107,7 +107,7 @@ int32_t CFile::read(uint8_t *ptr, size_t size) {
return -1;
}
int32_t CFile::write(const uint8_t *ptr, size_t size) {
int64_t CFile::write(const uint8_t *ptr, size_t size) {
if (iFd >= 0) {
size_t done = 0;
while (done < size) {

View File

@ -42,7 +42,7 @@ public:
int32_t read(uint8_t *ptr, size_t size);
int32_t write(const uint8_t *ptr, size_t size);
int64_t write(const uint8_t *ptr, size_t size);
int32_t fwrite(const char *format, ...);

View File

@ -132,10 +132,14 @@ int32_t FSUtils::CreateSubfolder(const char *fullpath) {
BOOL FSUtils::saveBufferToFile(const char *path, void *buffer, uint32_t size) {
CFile file(path, CFile::WriteOnly);
if (!file.isOpen()) {
DEBUG_FUNCTION_LINE("Failed to open %s\n", path);
DEBUG_FUNCTION_LINE_ERR("Failed to open %s\n", path);
return false;
}
if (file.write((const uint8_t *) buffer, size) != size) {
DEBUG_FUNCTION_LINE_ERR("Failed to write file %s\n", path);
file.close();
return false;
}
file.write((const uint8_t *) buffer, size);
file.close();
return true;
}