Skip to content

Commit

Permalink
Fix return value of lfs_rename()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tomscii authored and geky committed Jan 17, 2024
1 parent 3513ff1 commit 4f32738
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4f32738

Please sign in to comment.