Hi all,

POSIX.1-2001 says that link() should dereference symlinks. The Linux
kernel does not follow POSIX, so that calling cp with --no-dereference
and --link works as expected. However on non-Linux kernel, this does not
work as expected, the symlinks being dereferenced. This is even worse
with symlinks pointing to non-existing paths, where contrary to Linux,
cp fails in such cases.

I suggest to make regular copy of the symlink in such cases, to increase
portability of shell scripts. This is the purpose of the attached patch.

Regards,
Aurelien

-- 
  .''`.  Aurelien Jarno             | GPG: 1024D/F1BCDB73
 : :' :  Debian GNU/Linux developer | Electrical Engineer
 `. `'   [EMAIL PROTECTED]         | [EMAIL PROTECTED]
   `-    people.debian.org/~aurel32 | www.aurel32.net
--- coreutils-5.2.1.orig/src/copy.c     2005-09-19 00:35:32.000000000 +0200
+++ coreutils-5.2.1/src/copy.c  2005-09-19 00:34:53.000000000 +0200
@@ -1411,7 +1411,15 @@
        }
     }
 #endif
+/* According to POSIX.1-2001, a call to link() should dereference symlinks. cp 
+   called with the --no-dereference argument should not. */
+#ifdef LINK_FOLLOWS_SYMLINKS
+  /* For kernels that do not follow POSIX, don't call link() and make a copy. 
*/
+  else if (x->hard_link && !(S_ISLNK (src_mode) && x->dereference == 
DEREF_NEVER))
+#else
+  /* For kernels that follow POSIX, use link() in all cases. */
   else if (x->hard_link)
+#endif
     {
       preserve_metadata = 0;
       if (link (src_path, dst_path))

Attachment: signature.asc
Description: Digital signature

_______________________________________________
Bug-coreutils mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-coreutils

Reply via email to