[mpy/files] Fixed append implementation (#434)

This commit is contained in:
Maxime FRIESS
2020-12-10 21:30:54 +01:00
committed by GitHub
parent b343c5a02c
commit f202a4f902

View File

@@ -464,15 +464,8 @@ STATIC mp_obj_t file_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
file->record = Ion::Storage::sharedStorage()->recordNamed(file_name);
break;
case APPEND:
file->position = 0;
status = Ion::Storage::sharedStorage()->createRecordWithFullName(file_name, "", 0);
switch (status) {
case Ion::Storage::Record::ErrorStatus::NameTaken:
// setValue messes with empty buffer, so we delete record and re-create it.
file->record = Ion::Storage::sharedStorage()->recordNamed(file_name);
file->record.destroy();
break;
case Ion::Storage::Record::ErrorStatus::NotEnoughSpaceAvailable:
mp_raise_OSError(28);
break;
@@ -480,6 +473,7 @@ STATIC mp_obj_t file_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
break;
}
file->record = Ion::Storage::sharedStorage()->recordNamed(file_name);
file->position = file->record.value().size;
break;
}