changeset 12062:00e8f52bdef4

link: fix test failure on Solaris 9 link("file/",name) mistakenly succeeded. * lib/link.c (rpl_link): Don't assume link will catch bogus trailing slash on source. Signed-off-by: Eric Blake <ebb9@byu.net>
author Eric Blake <ebb9@byu.net>
date Wed, 23 Sep 2009 06:10:36 -0600
parents c47da311af77
children 6b9a61fbff48
files ChangeLog lib/link.c
diffstat 2 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2009-09-23  Eric Blake  <ebb9@byu.net>
 
+	link: fix test failure on Solaris 9
+	* lib/link.c (rpl_link): Don't assume link will catch bogus
+	trailing slash on source.
+
 	test-symlinkat: enhance test
 	* tests/test-readlink.c (main): Move guts...
 	* tests/test-readlink.h (test_readlink): ...into new file.
--- a/lib/link.c
+++ b/lib/link.c
@@ -162,11 +162,13 @@
       || (len2 && file2[len2 - 1] == '/'))
     {
       /* Let link() decide whether hard-linking directories is legal.
-         If stat() fails, link() will probably fail for the same
-         reason; so we only have to worry about successful stat() and
-         non-directory.  */
+         If stat() fails, then link() should fail for the same reason
+         (although on Solaris 9, link("file/","oops") mistakenly
+         succeeds); if stat() succeeds, require a directory.  */
       struct stat st;
-      if (stat (file1, &st) == 0 && !S_ISDIR (st.st_mode))
+      if (stat (file1, &st))
+        return -1;
+      if (!S_ISDIR (st.st_mode))
         {
           errno = ENOTDIR;
           return -1;