From 6ee45dde579d81028c6d323fc9fab0771384d0a4 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 12 Oct 2022 16:52:22 -0400 Subject: [PATCH] f_rename return value; add a test for rename dir inside itself --- extmod/vfs_fat.c | 2 -- lib/oofatfs/ff.c | 2 +- tests/extmod/vfs_fat_fileio2.py | 5 +++++ tests/extmod/vfs_fat_fileio2.py.exp | 1 + 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c index 64a3ce05f6..880eef7740 100644 --- a/extmod/vfs_fat.c +++ b/extmod/vfs_fat.c @@ -234,8 +234,6 @@ STATIC mp_obj_t fat_vfs_rename(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t path_ } if (res == FR_OK) { return mp_const_none; - } else if (res == FR_NO_PATH) { - mp_raise_OSError(MP_EINVAL); } else { mp_raise_OSError_fresult(res); } diff --git a/lib/oofatfs/ff.c b/lib/oofatfs/ff.c index d6fc7ebcc2..e6afd57800 100644 --- a/lib/oofatfs/ff.c +++ b/lib/oofatfs/ff.c @@ -4828,7 +4828,7 @@ FRESULT f_rename ( strlen(path_new) > strlen(path_old) && path_new[strlen(path_old)] == '/' && strncmp(path_old, path_new, strlen(path_old)) == 0) { - return FR_NO_PATH; + return FR_INVALID_NAME; } res = find_volume(fs, FA_WRITE); /* Get logical drive of the old object */ diff --git a/tests/extmod/vfs_fat_fileio2.py b/tests/extmod/vfs_fat_fileio2.py index 297d75a481..7c75a6d044 100644 --- a/tests/extmod/vfs_fat_fileio2.py +++ b/tests/extmod/vfs_fat_fileio2.py @@ -70,6 +70,11 @@ try: except OSError as e: print(e.errno == uerrno.ENOENT) +try: + vfs.rename("foo_dir", "foo_dir/inside_itself") +except OSError as e: + print(e.errno == uerrno.EINVAL) + # file in dir with open("foo_dir/file-in-dir.txt", "w+t") as f: f.write("data in file") diff --git a/tests/extmod/vfs_fat_fileio2.py.exp b/tests/extmod/vfs_fat_fileio2.py.exp index 2684053641..ed6e315328 100644 --- a/tests/extmod/vfs_fat_fileio2.py.exp +++ b/tests/extmod/vfs_fat_fileio2.py.exp @@ -1,6 +1,7 @@ True True True +True b'data in file' True [('sub_file.txt', 32768, 0, 11), ('file.txt', 32768, 0, 12)]