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:
authorChristopher Haster <geky@geky.net>2024-01-19 22:19:21 +0300
committerGitHub <noreply@github.com>2024-01-19 22:19:21 +0300
commitceb17a0f4ad466ea445c8c931ec19a944349b3e7 (patch)
tree45aefe9ba0be5eadd83410faf808efdd69c054a4
parenta8a09057775b2fb931e48c60de7ccc80966cca39 (diff)
parentf522ed907af5de03f13487d3e75704ecf1557733 (diff)
Merge pull request #917 from tomscii/fix_return_value_of_lfs_rename
Fix return value of lfs_rename()
-rw-r--r--lfs.c4
-rw-r--r--tests/test_dirs.toml13
2 files changed, 16 insertions, 1 deletions
diff --git a/lfs.c b/lfs.c
index 93b9b8f..9ad1683 100644
--- a/lfs.c
+++ b/lfs.c
@@ -3953,7 +3953,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;
diff --git a/tests/test_dirs.toml b/tests/test_dirs.toml
index 4262a1a..181dd6a 100644
--- a/tests/test_dirs.toml
+++ b/tests/test_dirs.toml
@@ -747,6 +747,11 @@ code = '''
lfs_file_open(&lfs, &file, "potato",
LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_ISDIR;
+ lfs_file_open(&lfs, &file, "tacoto", LFS_O_WRONLY | LFS_O_CREAT) => 0;
+ lfs_file_close(&lfs, &file) => 0;
+ lfs_rename(&lfs, "tacoto", "potato") => LFS_ERR_ISDIR;
+ lfs_rename(&lfs, "potato", "tacoto") => LFS_ERR_NOTDIR;
+
lfs_mkdir(&lfs, "/") => LFS_ERR_EXIST;
lfs_file_open(&lfs, &file, "/",
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_EXIST;
@@ -770,6 +775,10 @@ code = '''
lfs_dir_read(&lfs, &dir, &info) => 1;
assert(info.type == LFS_TYPE_DIR);
assert(strcmp(info.name, "potato") == 0);
+ lfs_dir_read(&lfs, &dir, &info) => 1;
+ assert(info.type == LFS_TYPE_REG);
+ assert(strcmp(info.name, "tacoto") == 0);
+ assert(info.size == 0);
lfs_dir_read(&lfs, &dir, &info) => 0;
lfs_dir_close(&lfs, &dir) => 0;
@@ -790,6 +799,10 @@ code = '''
lfs_dir_read(&lfs, &dir, &info) => 1;
assert(info.type == LFS_TYPE_DIR);
assert(strcmp(info.name, "potato") == 0);
+ lfs_dir_read(&lfs, &dir, &info) => 1;
+ assert(info.type == LFS_TYPE_REG);
+ assert(strcmp(info.name, "tacoto") == 0);
+ assert(info.size == 0);
lfs_dir_read(&lfs, &dir, &info) => 0;
lfs_dir_close(&lfs, &dir) => 0;
lfs_unmount(&lfs) => 0;