extmod/vfs_posix_file: Allow closing an already closed file.
Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
parent
c7aaee2b2b
commit
26b4ef4c46
|
@ -163,7 +163,11 @@ STATIC mp_uint_t vfs_posix_file_write(mp_obj_t o_in, const void *buf, mp_uint_t
|
|||
|
||||
STATIC mp_uint_t vfs_posix_file_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) {
|
||||
mp_obj_vfs_posix_file_t *o = MP_OBJ_TO_PTR(o_in);
|
||||
|
||||
if (request != MP_STREAM_CLOSE) {
|
||||
check_fd_is_open(o);
|
||||
}
|
||||
|
||||
switch (request) {
|
||||
case MP_STREAM_FLUSH: {
|
||||
int ret;
|
||||
|
|
|
@ -8,6 +8,15 @@ except (ImportError, AttributeError):
|
|||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
# We need a file for testing that doesn't already exist.
|
||||
# Skip the test if it does exist.
|
||||
temp_file = "micropy_test_file.txt"
|
||||
try:
|
||||
uos.stat(temp_file)
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
# getcwd and chdir
|
||||
curdir = uos.getcwd()
|
||||
|
@ -21,3 +30,19 @@ print(type(uos.stat("/")))
|
|||
|
||||
# listdir and ilistdir
|
||||
print(type(uos.listdir("/")))
|
||||
|
||||
# file create
|
||||
f = open(temp_file, "w")
|
||||
f.write("hello")
|
||||
f.close()
|
||||
|
||||
# close on a closed file should succeed
|
||||
f.close()
|
||||
|
||||
# file read
|
||||
f = open(temp_file, "r")
|
||||
print(f.read())
|
||||
f.close()
|
||||
|
||||
# remove
|
||||
uos.remove(temp_file)
|
||||
|
|
|
@ -2,3 +2,4 @@
|
|||
True
|
||||
<class 'tuple'>
|
||||
<class 'list'>
|
||||
hello
|
||||
|
|
|
@ -44,3 +44,6 @@ try:
|
|||
except OSError:
|
||||
print("OSError")
|
||||
f.close()
|
||||
|
||||
# close() on a closed file
|
||||
f.close()
|
||||
|
|
Loading…
Reference in New Issue