From: Eric Blake Date: Thu, 1 Oct 2009 00:57:02 +0000 (-0600) Subject: rename-dest-slash: fix NetBSD bug X-Git-Tag: v0.1~5395 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=0239f3316221451491f8befa7556e3fb8dfb1159;p=gnulib.git 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 --- diff --git a/ChangeLog b/ChangeLog index f13340f89..ba1cea5d9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2009-10-02 Eric Blake + 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. diff --git a/lib/rename-dest-slash.c b/lib/rename-dest-slash.c index 80660768a..2014fb1c4 100644 --- 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 #include "dirname.h" +#include "same-inode.h" #include "xalloc.h" static bool @@ -63,14 +64,22 @@ has_trailing_slash (char const *file) 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); diff --git a/modules/rename-dest-slash b/modules/rename-dest-slash index d45fe5bcf..c0bc98df4 100644 --- a/modules/rename-dest-slash +++ b/modules/rename-dest-slash @@ -6,8 +6,9 @@ lib/rename-dest-slash.c m4/rename-dest-slash.m4 Depends-on: -xalloc dirname +same-inode +xalloc configure.ac: gl_FUNC_RENAME_TRAILING_DEST_SLASH