extmod/vfs_posix_file: Allow closing an already closed file.

Signed-off-by: Damien George <damien@micropython.org>
pull/6876/head
Damien George 2021-02-11 22:53:36 +11:00
rodzic c7aaee2b2b
commit 26b4ef4c46
4 zmienionych plików z 34 dodań i 1 usunięć

Wyświetl plik

@ -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);
check_fd_is_open(o);
if (request != MP_STREAM_CLOSE) {
check_fd_is_open(o);
}
switch (request) {
case MP_STREAM_FLUSH: {
int ret;

Wyświetl plik

@ -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)

Wyświetl plik

@ -2,3 +2,4 @@
True
<class 'tuple'>
<class 'list'>
hello

Wyświetl plik

@ -44,3 +44,6 @@ try:
except OSError:
print("OSError")
f.close()
# close() on a closed file
f.close()