From 8b95b7ca5bcac0834c5318d6487c7964ab5105b6 Mon Sep 17 00:00:00 2001 From: crafcat7 Date: Sat, 3 Dec 2022 00:30:25 +0800 Subject: [PATCH] littlefs: Get and return the current error status before RMDIR execution type In some cases, deleting a folder will return unexpected results. For example, ENOENT should be returned when deleting a non-existent folder, but the result will return ENOTDIR. --- fs/littlefs/lfs_vfs.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/littlefs/lfs_vfs.c b/fs/littlefs/lfs_vfs.c index 5687ab15d7a..49bf16cf620 100644 --- a/fs/littlefs/lfs_vfs.c +++ b/fs/littlefs/lfs_vfs.c @@ -1324,8 +1324,14 @@ static int littlefs_mkdir(FAR struct inode *mountpt, FAR const char *relpath, static int littlefs_rmdir(FAR struct inode *mountpt, FAR const char *relpath) { struct stat buf; + int ret; + + ret = littlefs_stat(mountpt, relpath, &buf); + if (ret < 0) + { + return ret; + } - littlefs_stat(mountpt, relpath, &buf); if (S_ISDIR(buf.st_mode)) { return littlefs_unlink(mountpt, relpath);