pkg://fileutils-4.1-10.4.src.rpm:1292396/fileutils-4.0-samefile.patch
info downloads
--- fileutils-4.0/src/mv.c.samefile Sat Sep 19 13:09:23 1998
+++ fileutils-4.0/src/mv.c Mon Sep 13 13:00:34 1999
@@ -285,14 +285,36 @@
{
int dest_had_trailing_slash = strip_trailing_slashes_2 (dest);
int fail;
-
+ struct stat st_src, st_dst;
+
+ /*
+ * first check that we are not moving something onto itself. It is
+ * easier to do it here since no matter how you do it you can not move
+ * a file onto itself --gafton
+ */
+ fail = lstat(source, &st_src);
+ if (fail != 0)
+ error(1, 0, "can't stat source %s", source);
+ fail = lstat(dest, &st_dst);
+ /*
+ * don't bail if second stat fails. We could be renaming it. --notting
+ */
+ /* Now check that we are dealing with the same thing */
+ if (fail == 0 && st_src.st_dev == st_dst.st_dev &&
+ st_src.st_ino == st_dst.st_ino) {
+ /* Damn, it's the same */
+ error(0, 0, "Can't move %s into itself", source);
+ return 1;
+ }
+
/* In addition to when DEST is a directory, if DEST has a trailing
slash and neither SOURCE nor DEST is a directory, presume the target
is DEST/`basename source`. This converts `mv x y/' to `mv x y/x'.
This change means that the command `mv any file/' will now fail
rather than performing the move. The case when SOURCE is a
directory and DEST is not is properly diagnosed by do_move. */
-
+ /* --but this is detected earlier anyway --gafton */
+
if (dest_is_dir || (dest_had_trailing_slash && !is_real_dir (source)))
{
/* DEST is a directory; build full target filename. */