f_rename return value; add a test for rename dir inside itself

This commit is contained in:
Dan Halbert 2022-10-12 16:52:22 -04:00
parent 12085496f0
commit 6ee45dde57
4 changed files with 7 additions and 3 deletions

View File

@ -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) { if (res == FR_OK) {
return mp_const_none; return mp_const_none;
} else if (res == FR_NO_PATH) {
mp_raise_OSError(MP_EINVAL);
} else { } else {
mp_raise_OSError_fresult(res); mp_raise_OSError_fresult(res);
} }

View File

@ -4828,7 +4828,7 @@ FRESULT f_rename (
strlen(path_new) > strlen(path_old) && strlen(path_new) > strlen(path_old) &&
path_new[strlen(path_old)] == '/' && path_new[strlen(path_old)] == '/' &&
strncmp(path_old, path_new, strlen(path_old)) == 0) { 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 */ res = find_volume(fs, FA_WRITE); /* Get logical drive of the old object */

View File

@ -70,6 +70,11 @@ try:
except OSError as e: except OSError as e:
print(e.errno == uerrno.ENOENT) 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 # file in dir
with open("foo_dir/file-in-dir.txt", "w+t") as f: with open("foo_dir/file-in-dir.txt", "w+t") as f:
f.write("data in file") f.write("data in file")

View File

@ -1,6 +1,7 @@
True True
True True
True True
True
b'data in file' b'data in file'
True True
[('sub_file.txt', 32768, 0, 11), ('file.txt', 32768, 0, 12)] [('sub_file.txt', 32768, 0, 11), ('file.txt', 32768, 0, 12)]