Abhishekmishra2808 commented on code in PR #19585:
URL: https://github.com/apache/nuttx/pull/19585#discussion_r3695743348
##########
fs/vfs/fs_rename.c:
##########
@@ -162,57 +162,43 @@ static int pseudorename(FAR const char *oldpath, FAR
struct inode *oldinode,
* won't really be removed until we call inode_release();
*/
- inode_remove(newpath);
+ ret = inode_remove(newpath);
+ if (ret < 0 && ret != -EBUSY)
+ {
+ goto errout_with_lock;
+ }
+
#ifdef CONFIG_FS_NOTIFY
notify_unlink(newpath);
#endif
}
-
- inode_release(newinode);
- }
-
- /* Re-resolve the final destination parent after path rewrite. */
-
- SETUP_SEARCH(&pardesc, newpath, true);
- inode_find(&pardesc); /* pardesc.parent valid even if node not found */
- parnode = pardesc.node;
-
- ret = inode_checkperm(pardesc.parent, W_OK);
-
- /* inode_find() holds a reference on parnode; RELEASE_SEARCH() only
- * frees pardesc.buffer.
- */
-
- if (parnode != NULL)
- {
- inode_release(parnode);
- }
-
- RELEASE_SEARCH(&pardesc);
-
- if (ret < 0)
- {
- goto errout;
}
/* Create a new, empty inode at the destination location.
* NOTE that the new inode will be created with a reference count
* of zero.
*/
- inode_lock();
ret = inode_reserve(newpath, 0777, &newinode);
if (ret < 0)
{
- /* It is an error if a node at newpath already exists in the tree
- * OR if we fail to allocate memory for the new inode (and possibly
- * any new intermediate path segments).
- */
+ goto errout_with_lock;
+ }
- ret = -EEXIST;
+ /* Re-resolve the source under the same lock before unlinking it. */
+
+ SETUP_SEARCH(&olddesc, oldpath, true);
+ ret = inode_search(&olddesc);
+ if (ret < 0 || olddesc.node != oldinode)
+ {
+ inode_remove(newpath);
+ ret = -ENOENT;
+ RELEASE_SEARCH(&olddesc);
Review Comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]