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 e0a3baf73c347ebe4fe7ff150a0b507bd52f5239
Author: Marco Casaroli <[email protected]>
AuthorDate: Mon Oct 19 00:02:57 2026 +0200

    fs/userfs: Return EEXIST from rename() when the new path exists.
    
    The user file system server receives the rename request.  The server
    can be any program, and it does not have to replace an existing entry
    with the new name.  The VFS removed such an entry before the rename, so
    the servers did not have to do it.
    
    userfs_rename() now asks the server for the status of the new path.  If
    the path exists, it returns EEXIST.  The VFS can then remove the entry
    and call rename() again, as before.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 fs/userfs/fs_userfs.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/fs/userfs/fs_userfs.c b/fs/userfs/fs_userfs.c
index 427e903a893..cc7a83abfe1 100644
--- a/fs/userfs/fs_userfs.c
+++ b/fs/userfs/fs_userfs.c
@@ -2061,6 +2061,7 @@ static int userfs_rename(FAR struct inode *mountpt,
   FAR struct userfs_state_s *priv;
   FAR struct userfs_rename_request_s *req;
   FAR struct userfs_rename_response_s *resp;
+  struct stat buf;
   int oldpathlen;
   int newpathlen;
   ssize_t nsent;
@@ -2071,6 +2072,15 @@ static int userfs_rename(FAR struct inode *mountpt,
               mountpt->i_private != NULL);
   priv = mountpt->i_private;
 
+  /* The server may not replace an existing newrelpath.  EEXIST makes the
+   * VFS remove it first.
+   */
+
+  if (userfs_stat(mountpt, newrelpath, &buf) >= 0)
+    {
+      return -EEXIST;
+    }
+
   /* Check the path lengths */
 
   DEBUGASSERT(oldrelpath != NULL && newrelpath != NULL);

Reply via email to