changeset 12092:e3b5ec5715b7

rename-dest-slash: fix NetBSD bug rename("hard1","hard2") mistakenly removed the hard link "hard1". * lib/rename-dest-slash.c (rpl_rename_dest_slash): Detect hard links. * modules/rename-dest-slash (Depends-on): Add same-inode. Signed-off-by: Eric Blake <ebb9@byu.net>
author Eric Blake <ebb9@byu.net>
date Wed, 30 Sep 2009 18:57:02 -0600
parents 4884000a2d0c
children b07a0a61b0c1
files ChangeLog lib/rename-dest-slash.c modules/rename-dest-slash
diffstat 3 files changed, 19 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2009-10-02  Eric Blake  <ebb9@byu.net>
 
+	rename-dest-slash: fix NetBSD bug
+	* lib/rename-dest-slash.c (rpl_rename_dest_slash): Detect hard
+	links.
+	* modules/rename-dest-slash (Depends-on): Add same-inode.
+
 	rename-tests: new test, exposes several platform bugs
 	* modules/rename-tests: New file.
 	* tests/test-rename.h: Likewise.
--- a/lib/rename-dest-slash.c
+++ b/lib/rename-dest-slash.c
@@ -6,7 +6,7 @@
    (namely mv) relying on the rename syscall have more consistent
    semantics.
 
-   Copyright (C) 2006 Free Software Foundation, Inc.
+   Copyright (C) 2006, 2009 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -35,6 +35,7 @@
 #include <stdlib.h>
 
 #include "dirname.h"
+#include "same-inode.h"
 #include "xalloc.h"
 
 static bool
@@ -63,14 +64,22 @@
 int
 rpl_rename_dest_slash (char const *src, char const *dst)
 {
-  int ret_val = rename (src, dst);
+  struct stat sb;
+  struct stat db;
+  int ret_val;
+
+  if (lstat (src, &sb))
+    return -1;
+  if (lstat (dst, &db) == 0 && SAME_INODE (sb, db))
+    return 0;
+
+  ret_val = rename (src, dst);
 
   if (ret_val != 0 && errno == ENOENT && has_trailing_slash (dst))
     {
       int rename_errno = ENOENT;
 
       /* Fail now, unless SRC is a directory.  */
-      struct stat sb;
       if (lstat (src, &sb) == 0 && S_ISDIR (sb.st_mode))
 	{
 	  char *dst_temp = xstrdup (dst);
--- a/modules/rename-dest-slash
+++ b/modules/rename-dest-slash
@@ -6,8 +6,9 @@
 m4/rename-dest-slash.m4
 
 Depends-on:
+dirname
+same-inode
 xalloc
-dirname
 
 configure.ac:
 gl_FUNC_RENAME_TRAILING_DEST_SLASH