]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(do_link): Try to remove DEST even after renaming it.
authorJim Meyering <jim@meyering.net>
Mon, 18 Jan 1999 02:41:13 +0000 (02:41 +0000)
committerJim Meyering <jim@meyering.net>
Mon, 18 Jan 1999 02:41:13 +0000 (02:41 +0000)
This fixes a bug reported by Jamie Lokier.

src/ln.c

index 568171e9247bab0ca626c611e74e7787f074885c..093b9e6f43b0e90648f917df9cbcf8994f072393 100644 (file)
--- a/src/ln.c
+++ b/src/ln.c
@@ -283,7 +283,12 @@ do_link (const char *source, const char *dest)
                dest_backup = NULL;
            }
        }
-      else if (unlink (dest) && errno != ENOENT)
+
+      /* Try to unlink DEST even if we may have renamed it.  In some unusual
+        cases (when DEST and DEST_BACKUP are hard-links that refer to the
+        same file), rename succeeds and DEST remains.  If we didn't remove
+        DEST in that case, the subsequent LINKFUNC call would fail.  */
+      if (unlink (dest) && errno != ENOENT)
        {
          error (0, errno, _("cannot remove `%s'"), dest);
          return 1;