Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/littlefs-project/littlefs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Szilagyi <tom.szilagyi@altmail.se>2024-01-03 18:13:31 +0300
committerChristopher Haster <geky@geky.net>2024-01-17 09:06:52 +0300
commit4f32738cd6a861e9c3f077e86349f0c28ae5f589 (patch)
tree966e8bbac8225bdc90c510bca6604f2bf7c1336a
parent3513ff1afc1d67adb2e6f492f0b9bc0d798fcb0d (diff)
Fix return value of lfs_rename()
When lfs_rename() is called trying to rename (move) a file to an existing directory, LFS_ERR_ISDIR is (correctly) returned. However, in the opposite case, if one tries to rename (move) a directory to a path currently occupied by a regular file, LFS_ERR_NOTDIR should be returned (since the error is that the destination is NOT a directory), but in reality, LFS_ERR_ISDIR is returned in this case as well. This commit fixes the code so that in the latter case, LFS_ERR_NOTDIR is returned.
-rw-r--r--lfs.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/lfs.c b/lfs.c
index a152687..c7dc3eb 100644
--- a/lfs.c
+++ b/lfs.c
@@ -3940,7 +3940,9 @@ static int lfs_rawrename(lfs_t *lfs, const char *oldpath, const char *newpath) {
newoldid += 1;
}
} else if (lfs_tag_type3(prevtag) != lfs_tag_type3(oldtag)) {
- return LFS_ERR_ISDIR;
+ return (lfs_tag_type3(prevtag) == LFS_TYPE_DIR)
+ ? LFS_ERR_ISDIR
+ : LFS_ERR_NOTDIR;
} else if (samepair && newid == newoldid) {
// we're renaming to ourselves??
return 0;