[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 21doc-cp-r-portability.diff
From: |
Paul Eggert |
Subject: |
Re: 21doc-cp-r-portability.diff |
Date: |
Wed, 10 Nov 2004 16:11:52 -0800 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) |
Alexandre Duret-Lutz <address@hidden> writes:
> This minus `-r' just caught my eye.
> What should be preferred between `cp -R' and `cp -r'?
-R.
> Automake's lib/am/distdir.am uses `cp -R' and claims `cp -r' to
> be "almost always incorrect".
-R's behavior is defined by POSIX. -r's is not. With GNU cp, there's
no difference. With Solaris cp, -r reads from pipes instead of
replicating them, which is typically not what you want. For example:
$ mkdir d
$ cd d
$ ls
$ mkdir d
$ mkfifo d/fifo
$ (sleep 10; echo foo >d/fifo)& date; cp -r d e; date
[1] 2400
Wed Nov 10 16:04:31 PST 2004
Wed Nov 10 16:04:41 PST 2004
[1]+ Done ( sleep 10; echo foo >d/fifo )
$ ls -l d e
d:
total 0
prw-rw-r-- 1 eggert eggert 0 Nov 10 16:04 fifo
e:
total 16
-rw-rw-r-- 1 eggert eggert 4 Nov 10 16:04 fifo
Thanks for catching this. I installed the following patch:
2004-11-10 Paul Eggert <address@hidden>
* doc/autoconf.texi (Limitations of Usual Tools): Avoid cp -r;
use cp -R instead.
--- autoconf.texi.~1.838.~ 2004-11-10 13:51:48 -0800
+++ autoconf.texi 2004-11-10 16:08:43 -0800
@@ -11223,10 +11223,15 @@ newline encoding.
@item @command{cp}
@c ---------------
@prindex @command{cp}
+Avoid the @option{-r} option, since its behavior is not specified by
+Posix. Use @option{-R} instead. On @acronym{GNU} hosts the two options
+are equivalent, but on Solaris 9 hosts (for example) @command{cp -r}
+reads from pipes instead of replicating them.
+
Some @command{cp} implementations (e.g., BSD/OS 4.2) do not allow
trailing slashes at the end of nonexistent destination directories. To
avoid this problem, omit the trailing slashes. For example, use
address@hidden -r source /tmp/newdir} rather than @samp{cp -r source
address@hidden -R source /tmp/newdir} rather than @samp{cp -R source
/tmp/newdir/} if @file{/tmp/newdir} does not exist.
@c This is thanks to Ian.