GNU bug report logs - #15806
[cp] -R modifies dereferencing settings

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: coreutils; Severity: wishlist; Reported by: Gian Piero Carrubba <gpiero@HIDDEN>; dated Mon, 4 Nov 2013 23:38:02 UTC; Maintainer for coreutils is bug-coreutils@HIDDEN.

Message received at 15806 <at> debbugs.gnu.org:


Received: (at 15806) by debbugs.gnu.org; 8 Nov 2013 16:45:52 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Nov 08 11:45:52 2013
Received: from localhost ([127.0.0.1]:41765 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1VepBw-0006kr-2a
	for submit <at> debbugs.gnu.org; Fri, 08 Nov 2013 11:45:52 -0500
Received: from ramona.rm-rf.it ([149.154.157.136]:36007)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <gpiero@HIDDEN>) id 1VepBt-0006ka-2o
 for 15806 <at> debbugs.gnu.org; Fri, 08 Nov 2013 11:45:50 -0500
Received: from valentina.fdc.rm-rf.it (valentina.fdc.rm-rf.it [192.168.192.1])
 by ramona.rm-rf.it (Postfix) with ESMTP id 46EAD135
 for <15806 <at> debbugs.gnu.org>; Fri,  8 Nov 2013 17:45:41 +0100 (CET)
Received: from caimano.fdc.rm-rf.it (caimano.fdc.rm-rf.it [192.168.192.17])
 by valentina.fdc.rm-rf.it (Postfix) with ESMTP id 8250621139
 for <15806 <at> debbugs.gnu.org>; Fri,  8 Nov 2013 17:45:40 +0100 (CET)
Received: from gpiero (uid 1000) (envelope-from gpiero@HIDDEN) id 3c014
 by caimano.fdc.rm-rf.it (DragonFly Mail Agent v0.9);
 Fri, 08 Nov 2013 17:45:40 +0100
Date: Fri, 8 Nov 2013 17:45:40 +0100
From: Gian Piero Carrubba <gpiero@HIDDEN>
To: Jim Meyering <jim@HIDDEN>
Subject: Re: [cp] -R modifies dereferencing settings
Message-ID: <20131108164540.GC2303@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Disposition: inline
In-Reply-To: <CA+8g5KHZjkuzEC0nqfBxmeWoTV=vwpqyZa59WRgaU4R7Wuhnxg@HIDDEN>
 <20131104233706.GA5665@HIDDEN>
User-Agent: Mutt/1.5.21 (2010-09-15)
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 15806
Cc: 15806 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: 0.0 (/)

* [Tue, Nov 05, 2013 at 12:37:06AM +0100] Gian Piero Carrubba:
>1. leave `cp -R` acting as it currently does...
>
>...but properly document it. The texinfo doc already cites this 
>behaviour, but both the man page and the help (imo, the two most used  
>sources while searching for an option) don't. I would suggest adding 
>"Implies '--no-dereference'" to the description of the -r/-R option.

...except that it's not exactly true. If '-r' implied '-P', `cp -rL` 
would dereference and `cp -Lr` would not. Actually they both 
dereference, so a better wording is needed. Something along the line: 
"By default, does not dereference symbolic links in the source".

>= tests/cp/special-f.sh [2]
>This is unexpected. At a first look, the failure should be caused by 
>the following test not being fully inclusive:
>
>    -- src/copy.c:1930
>    else if (! S_ISDIR (dst_sb.st_mode)
>        /* Never unlink dst_name when in move mode.  */
>        && ! x->move_mode
>        && (x->unlink_dest_before_opening
>            || (x->preserve_links && 1 < dst_sb.st_nlink)
>            || (x->dereference == DEREF_NEVER
>                && !  S_ISREG (src_sb.st_mode))
>            ))
>
>I hadn't the time for investigate further, will do in the next days. 
>At the moment, however, I suspect the previous dereference settings was 
>simply masking and underlying issue.

Will diverge to another report, as imho it is a bug by itself.

>[2] A side note about this test. The comment seems to contradict the 
>code:
>
>    -- tests/cp/special-f.sh:28
>    # Without -f, expect it to fail
>    cp -R fifo e || fail=1
>
>As for my impression, it also contradicts POSIX specifications (w/o 
>-f it should fail). Anyway this belongs to another bug report.

mmh, no... a better reading of the specs was enough to understand that 
it should NOT fail, so the test is right (but the comment is 
misleading).

* [Thu, Nov 07, 2013 at 09:27:41AM -0800] Jim Meyering:
>My first reaction is that it would take a strong argument to justify
>changing the existing semantics. Have you compared the semantics
>of any other cp implementations?

I have to admit I have no strong argument, and I suspect I cannot obtain 
one just by comparing different implementations, given that this 
behaviour is "implementation dependant" (so different implementations 
differ in this regard).

Just for reference, both cp implementations on Solaris 10 dereference:

$ echo TEST > file ; ln -s file link
$ for o in "" -R -r -PR -Pr -RP -rP ; do /usr/bin/cp $o link cp$o ; 
/usr/xpg4/bin/cp $o link cp-xpg4$o ; done
$ ls -liog
      678491 -rw-r--r--   1       5 Nov  8 16:55 cp
      678499 lrwxrwxrwx   1       4 Nov  8 16:55 cp-Pr -> file
      678497 lrwxrwxrwx   1       4 Nov  8 16:55 cp-PR -> file
      678495 -rw-r--r--   1       5 Nov  8 16:55 cp-r
      678493 -rw-r--r--   1       5 Nov  8 16:55 cp-R
      678503 lrwxrwxrwx   1       4 Nov  8 16:55 cp-rP -> file
      678501 lrwxrwxrwx   1       4 Nov  8 16:55 cp-RP -> file
      678492 -rw-r--r--   1       5 Nov  8 16:55 cp-xpg4
      678500 lrwxrwxrwx   1       4 Nov  8 16:55 cp-xpg4-Pr -> file
      678498 lrwxrwxrwx   1       4 Nov  8 16:55 cp-xpg4-PR -> file
      678496 -rw-r--r--   1       5 Nov  8 16:55 cp-xpg4-r
      678494 -rw-r--r--   1       5 Nov  8 16:55 cp-xpg4-R
      678504 lrwxrwxrwx   1       4 Nov  8 16:55 cp-xpg4-rP -> file
      678502 lrwxrwxrwx   1       4 Nov  8 16:55 cp-xpg4-RP -> file
      678489 -rw-r--r--   1       5 Nov  8 16:54 file
      678490 lrwxrwxrwx   1       4 Nov  8 16:54 link -> file

The same is true for AIX 6.1:

$ for o in "" -R -r -P -PR -Pr -RP -rP ; do cp $o link cp$o ; done
$ ls -liog
      32831 -rw-r--r--    1          5 Nov 08 16:53 cp
      32834 lrwxrwxrwx    1          4 Nov 08 16:53 cp-P
      32835 lrwxrwxrwx    1          4 Nov 08 16:53 cp-PR
      32836 lrwxrwxrwx    1          4 Nov 08 16:53 cp-Pr
      32832 -rw-r--r--    1          5 Nov 08 16:53 cp-R
      32837 lrwxrwxrwx    1          4 Nov 08 16:53 cp-RP
      32833 -rw-r--r--    1          5 Nov 08 16:53 cp-r
      32838 lrwxrwxrwx    1          4 Nov 08 16:53 cp-rP
      32829 -rw-r--r--    1          5 Nov 08 16:50 file
      32830 lrwxrwxrwx    1          4 Nov 08 16:50 link

On the other hand, if I recall correctly, the FreeBSD implementation 
acts like the coreutils one (doesn't dereference). Don't know about 
other implementations.

Ciao,
Gian Piero.




Information forwarded to bug-coreutils@HIDDEN:
bug#15806; Package coreutils. Full text available.

Message received at 15806 <at> debbugs.gnu.org:


Received: (at 15806) by debbugs.gnu.org; 7 Nov 2013 17:28:11 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Nov 07 12:28:11 2013
Received: from localhost ([127.0.0.1]:39588 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1VeTNK-0002hy-Ac
	for submit <at> debbugs.gnu.org; Thu, 07 Nov 2013 12:28:10 -0500
Received: from mail-pd0-f178.google.com ([209.85.192.178]:36439)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <meyering@HIDDEN>) id 1VeTNH-0002hW-DM
 for 15806 <at> debbugs.gnu.org; Thu, 07 Nov 2013 12:28:08 -0500
Received: by mail-pd0-f178.google.com with SMTP id x10so891546pdj.37
 for <15806 <at> debbugs.gnu.org>; Thu, 07 Nov 2013 09:28:01 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
 h=mime-version:sender:in-reply-to:references:from:date:message-id
 :subject:to:cc:content-type;
 bh=l1Km4nuy3Mul+xioKQZzOPIihwW59KxegYlV7669cqw=;
 b=n+Ou4EufavobO6Y0lJNK4vFp28QM/quU2j+viUgj8YOUWO3CfMAhbNwuj4lNZxhjX3
 w0q/0T640lPBul8rj/jeSMLUhEFpsnhEyFodmtRPBlNTnxUQUqs6UXL1T1G7ID1DO6dD
 vJxO+pdwN0negw5B6yT84Sk2fJH0u8v5QaeykIbf0CjJvii8Yp/JGx2LcFl2MGB7Dm5T
 ofxlxVcXFlIaQ014pYXqKL3TxPevI6mZIDI6Dt8WWN0xftpB0HK8aKqeuN+lOnjBygVP
 tKUGX+qKwBQByFO3Okxw9qVuwp6h4/JvdgQfulUxdDsYZDXYOWWkk+nr4MfmL533MOSY
 g9Vg==
X-Received: by 10.68.134.6 with SMTP id pg6mr10208279pbb.67.1383845281796;
 Thu, 07 Nov 2013 09:28:01 -0800 (PST)
MIME-Version: 1.0
Received: by 10.68.6.66 with HTTP; Thu, 7 Nov 2013 09:27:41 -0800 (PST)
In-Reply-To: <20131104233706.GA5665@HIDDEN>
References: <20131104233706.GA5665@HIDDEN>
From: Jim Meyering <jim@HIDDEN>
Date: Thu, 7 Nov 2013 09:27:41 -0800
X-Google-Sender-Auth: a6kvqt8JIX3KDfhoRjt7eRM6zf4
Message-ID: <CA+8g5KHZjkuzEC0nqfBxmeWoTV=vwpqyZa59WRgaU4R7Wuhnxg@HIDDEN>
Subject: Re: bug#15806: [cp] -R modifies dereferencing settings
To: Gian Piero Carrubba <gpiero@HIDDEN>
Content-Type: text/plain; charset=ISO-8859-1
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 15806
Cc: 15806 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: 0.0 (/)

On Mon, Nov 4, 2013 at 3:37 PM, Gian Piero Carrubba <gpiero@HIDDEN> wrote:
> Severity: wishlist
>
> Please Cc: me as I'm not subscribed.
>
> POSIX.1-2008 (ed. 2013) [0] states:
>
>     If source_file is a file of type symbolic link:
>
>     If the -R option was not specified, cp shall take actions based on
>     the type and contents of the file referenced by the symbolic link,
>     and not by the symbolic link itself, unless the -P option was
>     specified.
>
> So far, so good. As far as I know, coreutils' cp fully respect this.
>
>     If the -R option was specified:
>
>     If none of the options -H, -L, nor -P were specified, it is
>     unspecified which of -H, -L, or -P will be used as a default.
>
> Somewhere in the past, coreutils team has opted for using '-P' (DEREF_NEVER)
> in this case.  Anyway this leads to an inconsistence in the behaviour of cp:
>
>     $ touch file ; ln -s file symlink ; for o in "" -r ; do cp $o
>     symlink cp$o ; done ; ls -liog
>     total 0
>     8224776 -rw-r--r-- 1 0 Nov  4 23:15 cp
>     8224777 lrwxrwxrwx 1 4 Nov  4 23:15 cp-r -> file
>     8224774 -rw-r--r-- 1 0 Nov  4 23:15 file
>     8224775 lrwxrwxrwx 1 4 Nov  4 23:15 symlink -> file
>
> What wrong with it ? The problem is that we got a modified dereference
> setting just by using '--recursive', an unrelated option. Moreover,
> recursion and dereferencing are orthogonal features and there's no reason
> one should imply the other.
>
> As for my opinion, there are three possibilities for, at least, reduce this
> perceived inconsistency.
> 1. leave `cp -R` acting as it currently does...
>
> ...but properly document it. The texinfo doc already cites this behaviour,
> but both the man page and the help (imo, the two most used  sources while
> searching for an option) don't. I would suggest adding "Implies
> '--no-dereference'" to the description of the -r/-R option.

Thanks for your report and the patch.

My first reaction is that it would take a strong argument to justify
changing the existing semantics. Have you compared the semantics
of any other cp implementations?




Information forwarded to bug-coreutils@HIDDEN:
bug#15806; Package coreutils. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 4 Nov 2013 23:37:37 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Nov 04 18:37:37 2013
Received: from localhost ([127.0.0.1]:34786 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1VdTiC-0004bz-3r
	for submit <at> debbugs.gnu.org; Mon, 04 Nov 2013 18:37:37 -0500
Received: from eggs.gnu.org ([208.118.235.92]:35752)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <gpiero@HIDDEN>) id 1VdTi7-0004bh-Ki
 for submit <at> debbugs.gnu.org; Mon, 04 Nov 2013 18:37:32 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <gpiero@HIDDEN>) id 1VdThy-0003Pf-2W
 for submit <at> debbugs.gnu.org; Mon, 04 Nov 2013 18:37:26 -0500
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,UNPARSEABLE_RELAY
 autolearn=disabled version=3.3.2
Received: from lists.gnu.org ([2001:4830:134:3::11]:43917)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <gpiero@HIDDEN>) id 1VdThx-0003Pb-VH
 for submit <at> debbugs.gnu.org; Mon, 04 Nov 2013 18:37:21 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:37456)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <gpiero@HIDDEN>) id 1VdTht-0006Ew-J3
 for bug-coreutils@HIDDEN; Mon, 04 Nov 2013 18:37:21 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <gpiero@HIDDEN>) id 1VdThp-0003OW-Ek
 for bug-coreutils@HIDDEN; Mon, 04 Nov 2013 18:37:17 -0500
Received: from ramona.rm-rf.it ([149.154.157.136]:51534)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <gpiero@HIDDEN>) id 1VdThp-0003OF-4a
 for bug-coreutils@HIDDEN; Mon, 04 Nov 2013 18:37:13 -0500
Received: from valentina.fdc.rm-rf.it (valentina.fdc.rm-rf.it [192.168.192.1])
 by ramona.rm-rf.it (Postfix) with ESMTP id 9D5BD376
 for <bug-coreutils@HIDDEN>; Tue,  5 Nov 2013 00:37:09 +0100 (CET)
Received: from caimano.fdc.rm-rf.it (caimano.fdc.rm-rf.it [192.168.192.17])
 by valentina.fdc.rm-rf.it (Postfix) with ESMTP id 537421FC1B
 for <bug-coreutils@HIDDEN>; Tue,  5 Nov 2013 00:37:08 +0100 (CET)
Received: from gpiero (uid 1000) (envelope-from gpiero@HIDDEN) id 3c014
 by caimano.fdc.rm-rf.it (DragonFly Mail Agent v0.9);
 Tue, 05 Nov 2013 00:37:06 +0100
Date: Tue, 5 Nov 2013 00:37:06 +0100
From: Gian Piero Carrubba <gpiero@HIDDEN>
To: bug-coreutils@HIDDEN
Subject: [cp] -R modifies dereferencing settings
Message-ID: <20131104233706.GA5665@HIDDEN>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="45Z9DzgjV8m4Oswq"
Content-Disposition: inline
User-Agent: Mutt/1.5.21 (2010-09-15)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic]
X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address
 (bad octet value).
X-Received-From: 2001:4830:134:3::11
X-Spam-Score: -5.0 (-----)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -5.0 (-----)


--45Z9DzgjV8m4Oswq
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Disposition: inline

Severity: wishlist

Please Cc: me as I'm not subscribed.

POSIX.1-2008 (ed. 2013) [0] states:

     If source_file is a file of type symbolic link:

     If the -R option was not specified, cp shall take actions based on
     the type and contents of the file referenced by the symbolic link,
     and not by the symbolic link itself, unless the -P option was
     specified.

So far, so good. As far as I know, coreutils' cp fully respect this.

     If the -R option was specified:

     If none of the options -H, -L, nor -P were specified, it is
     unspecified which of -H, -L, or -P will be used as a default.

Somewhere in the past, coreutils team has opted for using '-P' 
(DEREF_NEVER) in this case.  Anyway this leads to an inconsistence in 
the behaviour of cp:

     $ touch file ; ln -s file symlink ; for o in "" -r ; do cp $o
     symlink cp$o ; done ; ls -liog
     total 0
     8224776 -rw-r--r-- 1 0 Nov  4 23:15 cp
     8224777 lrwxrwxrwx 1 4 Nov  4 23:15 cp-r -> file
     8224774 -rw-r--r-- 1 0 Nov  4 23:15 file
     8224775 lrwxrwxrwx 1 4 Nov  4 23:15 symlink -> file

What wrong with it ? The problem is that we got a modified dereference 
setting just by using '--recursive', an unrelated option. Moreover, 
recursion and dereferencing are orthogonal features and there's no 
reason one should imply the other.

As for my opinion, there are three possibilities for, at least, reduce 
this perceived inconsistency. 

1. leave `cp -R` acting as it currently does...

...but properly document it. The texinfo doc already cites this 
behaviour, but both the man page and the help (imo, the two most used  
sources while searching for an option) don't. I would suggest adding 
"Implies '--no-dereference'" to the description of the -r/-R option.

2. let `cp -R` act as if `-L` is used.

This is my preferred option, but it's also the most invasive. All the 
scripts using `cp -r` for copying a directory tree without dereferencing 
the symbolic links would fail. The texinfo doc warns against that use 
[1]:

     -- doc/coreutils.texi:8334
     [...] It is not portable to use
     @option{-r} to copy symbolic links or special files.  On some
     non-GNU systems, @option{-r} implies the equivalent of
     @option{-L} and @option{--copy-contents} for historical reasons.
     Also, it is not portable to use @option{-R} to copy symbolic links
     unless you also specify @option{-P}, as POSIX allows
     implementations that dereference symbolic links by default.

so maybe this option could be considered. But honestly, despite being my 
preferred option (i.e.: the one I would implement if I had to write a 
'cp' utility from scratch), I'm not sure I can endorse it as it would be 
highly backward incompatible.

3. let `cp -R` act as if `-H` is used.

This is a sort of compromise between the other two options. It gains 
some consistency ( `cp` and `cp -R` would act the same with regard to 
dereferencing the symlinks passed on the command line ) and would 
preserve a certain level of backward compatibility. I expect the 
percentage of real-case scripts that would be broken by this change to 
be really minimal.
I don't particularly like this option, but if option 2. is judged 
impractical (as it probably is), I personally largely prefer this 
solution over option 1.

The attached preliminary patch implements option 3.

After applying the patch the following tests fail:

= tests/cp/r-vs-symlink.sh
This is expected, as it is the point of the patch. Anyway the comments 
in the test file are suspicious:

     # cp -r should not create symlinks.  Fixed in fileutils-4.1.5.
     # Restored old behavior (whereby cp -r preserves symlinks) in 4.1.6,
     # though now such usage evokes a warning:
     # cp: 'slink': WARNING: using -r to copy symbolic links is not
     # portable

So maybe a similar change (probably option 2. above) was implemented, 
and reverted, in the past ? I wasn't able to find a reference to it in 
the Changelog, so cannot tell why it has been reverted. Anyway the 
warning cited in the comment doesn't seem to exist anymore.

= tests/cp/special-f.sh [2]
This is unexpected. At a first look, the failure should be caused by the 
following test not being fully inclusive:

     -- src/copy.c:1930
     else if (! S_ISDIR (dst_sb.st_mode)
         /* Never unlink dst_name when in move mode.  */
         && ! x->move_mode
         && (x->unlink_dest_before_opening
             || (x->preserve_links && 1 < dst_sb.st_nlink)
             || (x->dereference == DEREF_NEVER
                 && !  S_ISREG (src_sb.st_mode))
             ))

I hadn't the time for investigate further, will do in the next days. At 
the moment, however, I suspect the previous dereference settings was 
simply masking and underlying issue.

Ciao,
Gian Piero.

[0] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/cp.html

[1] Anyway I'm not sure why it differentiates between '-r' and '-R', 
given that in coreutils' cp they are aliases:

     -- src/copy.c:1045
     case 'r':
     case 'R':
       x.recursive = true;
       break;

[2] A side note about this test. The comment seems to contradict the 
code:

     -- tests/cp/special-f.sh:28
     # Without -f, expect it to fail
     cp -R fifo e || fail=1

As for my impression, it also contradicts POSIX specifications (w/o -f 
it should fail). Anyway this belongs to another bug report.

--45Z9DzgjV8m4Oswq
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment; filename="draft.patch"

Tue Nov  5 00:35:28 CET 2013  Gian Piero Carrubba <gpiero@HIDDEN>
  * DRAFT
diff -rN -u old-dereference-R/src/copy.h new-dereference-R/src/copy.h
--- old-dereference-R/src/copy.h	2013-11-05 00:35:44.062894654 +0100
+++ new-dereference-R/src/copy.h	2013-11-05 00:35:44.066894686 +0100
@@ -68,10 +68,8 @@
 /* How to handle symbolic links.  */
 enum Dereference_symlink
 {
-  DEREF_UNDEFINED = 1,
-
   /* Copy the symbolic link itself.  -P  */
-  DEREF_NEVER,
+  DEREF_NEVER = 1,
 
   /* If the symbolic is a command line argument, then copy
      its referent.  Otherwise, copy the symbolic link itself.  -H  */
diff -rN -u old-dereference-R/src/cp.c new-dereference-R/src/cp.c
--- old-dereference-R/src/cp.c	2013-11-05 00:35:44.062894654 +0100
+++ new-dereference-R/src/cp.c	2013-11-05 00:35:44.066894686 +0100
@@ -768,7 +768,7 @@
 {
   cp_options_default (x);
   x->copy_as_regular = true;
-  x->dereference = DEREF_UNDEFINED;
+  x->dereference = DEREF_COMMAND_LINE_ARGUMENTS;
   x->unlink_dest_before_opening = false;
   x->unlink_dest_after_failed_open = false;
   x->hard_link = false;
@@ -1133,15 +1133,6 @@
                                    version_control_string)
                    : no_backups);
 
-  if (x.dereference == DEREF_UNDEFINED)
-    {
-      if (x.recursive)
-        /* This is compatible with FreeBSD.  */
-        x.dereference = DEREF_NEVER;
-      else
-        x.dereference = DEREF_ALWAYS;
-    }
-
   if (x.recursive)
     x.copy_as_regular = copy_contents;
 

--45Z9DzgjV8m4Oswq--




Acknowledgement sent to Gian Piero Carrubba <gpiero@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-coreutils@HIDDEN. Full text available.
Report forwarded to bug-coreutils@HIDDEN:
bug#15806; Package coreutils. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Mon, 25 Nov 2019 12:00:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.