fs/vfs: Remove the redundancy file name comparison in mountptrename
@@ -310,7 +310,17 @@ static int mountptrename(FAR const char *oldpath, FAR struct inode *oldinode,
goto errout_with_newinode;
}
- /* Does a directory entry already exist at the 'rewrelpath'? And is it
+ /* If oldrelpath and newrelpath are the same, then this is an attempt
+ * to move the directory entry onto itself. Let's not but say we did.
+ */
+
+ if (strcmp(oldrelpath, newrelpath) == 0)
+ {
+ ret = OK;
+ goto errout_with_newinode; /* Same name, this is not an error case. */
+ }
+
+ /* Does a directory entry already exist at the 'newrelpath'? And is it
* not the same directory entry that we are moving?
*
* If the directory entry at the newrelpath is a regular file, then that
@@ -318,23 +328,15 @@ static int mountptrename(FAR const char *oldpath, FAR struct inode *oldinode,
*
* If the directory entry at the target is a directory, then the source
* file should be moved "under" the directory, i.e., if newrelpath is a
- * directory, then rename(b,a) should use move the olrelpath should be
+ * directory, then rename(b,a) should use move the oldrelpath should be
* moved as if rename(b,a/basename(b)) had been called.
*/
- if (oldinode->u.i_mops->stat != NULL &&
- strcmp(oldrelpath, newrelpath) != 0)
+ if (oldinode->u.i_mops->stat != NULL)
{
struct stat buf;
next_subdir:
- /* Something exists for this directory entry. Do nothing in the
- * degenerate case where a directory or file is being moved to
- * itself.
- */
-
- if (strcmp(oldrelpath, newrelpath) != 0)
- {
ret = oldinode->u.i_mops->stat(oldinode, newrelpath, &buf);
if (ret >= 0)
{
@@ -389,7 +391,7 @@ next_subdir:
else
{
/* No.. newrelpath must refer to a regular file. Make sure
- * that the file at the olrelpath actually exists before
+ * that the file at the oldrelpath actually exists before
* performing any further actions with newrelpath
*/
@@ -413,22 +415,12 @@ next_subdir:
}
}
}
- }
-
- /* Just declare success of the oldrepath and the newrelpath point to
- * the same directory entry. That directory entry should have been
- * stat'ed above to assure that it exists.
- */
- ret = OK;
- if (strcmp(oldrelpath, newrelpath) != 0)
- {
/* Perform the rename operation using the relative paths at the common
* mountpoint.
*/
ret = oldinode->u.i_mops->rename(oldinode, oldrelpath, newrelpath);
- }
errout_with_newinode:
inode_release(newinode);
