This is an automated email from the ASF dual-hosted git repository.
GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 55f026bd278 fs/vfs: preserve names when renaming hard links to the
same file
55f026bd278 is described below
commit 55f026bd278bb23fd0ed9467e186d5cfc30b3009
Author: guohao15 <[email protected]>
AuthorDate: Fri Nov 27 01:13:05 2026 +0800
fs/vfs: preserve names when renaming hard links to the same file
If the source and target of rename are hard links to the same file,
return success without changing either name.
Compare the underlying inode before removing a destination. A no-op must
also bypass rename notifications because no directory entry has moved.
Signed-off-by: guohao15 <[email protected]>
Signed-off-by: jingfei <[email protected]>
---
fs/vfs/fs_rename.c | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/fs/vfs/fs_rename.c b/fs/vfs/fs_rename.c
index 90ed36b0d39..e64b1e2ac01 100644
--- a/fs/vfs/fs_rename.c
+++ b/fs/vfs/fs_rename.c
@@ -112,18 +112,34 @@ static int pseudorename(FAR const char *oldpath, FAR
struct inode *oldinode,
ret = inode_search(&newdesc, &newinode);
if (ret >= 0)
{
+ FAR struct inode *oldtarget = oldinode;
+ FAR struct inode *newtarget = newinode;
+
/* We found it. Get the search results */
DEBUGASSERT(newinode != NULL);
- /* If the old and new inodes are the same, then this is an attempt to
- * move the directory entry onto itself. Let's not but say we did.
+#ifdef CONFIG_FS_LINKS
+ if (INODE_IS_HARDLINK(oldtarget))
+ {
+ oldtarget = oldtarget->i_private;
+ }
+
+ if (INODE_IS_HARDLINK(newtarget))
+ {
+ newtarget = newtarget->i_private;
+ }
+#endif
+
+ /* POSIX requires both names to remain when they refer to the same
+ * file. No entry moves, so no rename notification should be sent.
*/
- if (oldinode == newinode)
+ if (oldtarget == newtarget)
{
- ret = OK;
- goto errout_with_newsearch;
+ inode_search_release(&newdesc);
+ inode_unlock();
+ return OK;
}
#ifndef CONFIG_DISABLE_MOUNTPOINT