This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit d661061c1d05bc7407d0e115ad64a95edceba848
Author: Marco Casaroli <[email protected]>
AuthorDate: Mon Oct 19 00:02:57 2026 +0200

    fs/mnemofs: Return EEXIST from rename() when the new path exists.
    
    mfs_dir_rename() adds a directory entry with the new name.  It does not
    look for an entry that already has this name.  The VFS removed such an
    entry before the rename, so this was not visible.
    
    mnemofs_rename() now returns EEXIST when the new path exists.  The VFS
    can then remove the entry and call rename() again.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 fs/mnemofs/mnemofs.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/fs/mnemofs/mnemofs.c b/fs/mnemofs/mnemofs.c
index 136579b06a3..1bcd7219d7c 100644
--- a/fs/mnemofs/mnemofs.c
+++ b/fs/mnemofs/mnemofs.c
@@ -1851,6 +1851,7 @@ static int mnemofs_rename(FAR struct inode *mountpt,
                           FAR const char *newrelpath)
 {
   FAR struct mfs_sb_s *sb;
+  struct stat buf;
   int ret;
 
   sb = mnemofs_mountpt_to_sb(mountpt);
@@ -1861,6 +1862,16 @@ static int mnemofs_rename(FAR struct inode *mountpt,
       return ret;
     }
 
+  /* mfs_dir_rename() cannot replace an existing newrelpath.  EEXIST makes
+   * the VFS remove it first.
+   */
+
+  if (mfs_dir_stat(sb, newrelpath, &buf) == OK)
+    {
+      mnemofs_unlock(sb);
+      return -EEXIST;
+    }
+
   ret = mfs_dir_rename(sb, oldrelpath, newrelpath);
   if (ret < 0)
     {

Reply via email to