aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe Slater <joe.slater@windriver.com>2020-08-27 08:22:18 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2020-08-27 08:22:42 +0100
commitd6b1b13c268d7246f0288d32d6b5eccc658cff4e (patch)
tree00c97b686e6c08d9b30345f4155681c9ca520be6
parent7b4b22bd6ca60fb23393ce088347ffe33a601c1d (diff)
downloadpseudo-d6b1b13c268d7246f0288d32d6b5eccc658cff4e.tar.gz
pseudo-d6b1b13c268d7246f0288d32d6b5eccc658cff4e.tar.bz2
pseudo-d6b1b13c268d7246f0288d32d6b5eccc658cff4e.zip
pseudo: fix renaming to self
The pseudo rename guts test for an item being renamed to itself, only after information about it has been deleted. We move the test to before we play with the database. Note that pseudo does not support renameat2(). Signed-off-by: Joe Slater <joe.slater@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--ports/unix/guts/rename.c14
-rw-r--r--ports/unix/guts/renameat.c14
2 files changed, 16 insertions, 12 deletions
diff --git a/ports/unix/guts/rename.c b/ports/unix/guts/rename.c
index 5073c71..7e4a499 100644
--- a/ports/unix/guts/rename.c
+++ b/ports/unix/guts/rename.c
@@ -29,6 +29,14 @@
newrc = base_lstat(newpath, &newbuf);
oldrc = base_lstat(oldpath, &oldbuf);
+ /* nothing to do for a "rename" of a link to itself */
+ if (newrc != -1 && oldrc != -1 &&
+ newbuf.st_dev == oldbuf.st_dev &&
+ newbuf.st_ino == oldbuf.st_ino) {
+ pseudo_debug(PDBGF_OP, "rename: paths are the same\n");
+ return real_rename(oldpath, newpath);
+ }
+
errno = save_errno;
/* newpath must be removed. */
@@ -58,12 +66,6 @@
return rc;
}
save_errno = errno;
- /* nothing to do for a "rename" of a link to itself */
- if (newrc != -1 && oldrc != -1 &&
- newbuf.st_dev == oldbuf.st_dev &&
- newbuf.st_ino == oldbuf.st_ino) {
- return rc;
- }
/* rename(3) is not mv(1). rename(file, dir) fails; you must provide
* the corrected path yourself. You can rename over a directory only
diff --git a/ports/unix/guts/renameat.c b/ports/unix/guts/renameat.c
index 735a60a..8064818 100644
--- a/ports/unix/guts/renameat.c
+++ b/ports/unix/guts/renameat.c
@@ -41,6 +41,14 @@
newrc = base_fstatat(newdirfd, newpath, &newbuf, AT_SYMLINK_NOFOLLOW);
#endif
+ /* nothing to do for a "rename" of a link to itself */
+ if (newrc != -1 && oldrc != -1 &&
+ newbuf.st_dev == oldbuf.st_dev &&
+ newbuf.st_ino == oldbuf.st_ino) {
+ pseudo_debug(PDBGF_OP, "renameat: paths are the same\n");
+ return real_renameat(olddirfd, oldpath, newdirfd, newpath);
+ }
+
errno = save_errno;
/* newpath must be removed. */
@@ -71,12 +79,6 @@
return rc;
}
save_errno = errno;
- /* nothing to do for a "rename" of a link to itself */
- if (newrc != -1 && oldrc != -1 &&
- newbuf.st_dev == oldbuf.st_dev &&
- newbuf.st_ino == oldbuf.st_ino) {
- return rc;
- }
/* rename(3) is not mv(1). rename(file, dir) fails; you must provide
* the corrected path yourself. You can rename over a directory only