summaryrefslogtreecommitdiff
path: root/extmod/vfs_fat_file.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-10-24 12:59:20 +1100
committerDamien George <damien.p.george@gmail.com>2016-10-24 12:59:20 +1100
commit56942019309645781d330312f5944db2d4cb5cd7 (patch)
treef5410a2c3d933dad4b1423ec093fe97f70bd5607 /extmod/vfs_fat_file.c
parent06e703290640ed6326bf70e172c25be92799591f (diff)
extmod/vfs_fat_file: Make file.close() a no-op if file already closed.
As per CPython semantics. In particular, file.__del__() should not raise an exception if the file is already closed.
Diffstat (limited to 'extmod/vfs_fat_file.c')
-rw-r--r--extmod/vfs_fat_file.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/extmod/vfs_fat_file.c b/extmod/vfs_fat_file.c
index e269ef593..76ac23685 100644
--- a/extmod/vfs_fat_file.c
+++ b/extmod/vfs_fat_file.c
@@ -120,9 +120,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(file_obj_flush_obj, file_obj_flush);
STATIC mp_obj_t file_obj_close(mp_obj_t self_in) {
pyb_file_obj_t *self = MP_OBJ_TO_PTR(self_in);
- FRESULT res = f_close(&self->fp);
- if (res != FR_OK) {
- mp_raise_OSError(fresult_to_errno_table[res]);
+ // if fs==NULL then the file is closed and in that case this method is a no-op
+ if (self->fp.fs != NULL) {
+ FRESULT res = f_close(&self->fp);
+ if (res != FR_OK) {
+ mp_raise_OSError(fresult_to_errno_table[res]);
+ }
}
return mp_const_none;
}