From darius@chowder.gsoft.com.au  Wed Jun 12 22:22:44 2002
Return-Path: <darius@chowder.gsoft.com.au>
Received: from chowder.gsoft.com.au (chowder.gsoft.com.au [203.38.152.100])
	by hub.freebsd.org (Postfix) with ESMTP id 1A72337B411
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 12 Jun 2002 22:22:42 -0700 (PDT)
Received: from chowder.gsoft.com.au (localhost [127.0.0.1])
	by chowder.gsoft.com.au (8.12.3/8.12.3) with ESMTP id g5D5Mdm0000239
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 13 Jun 2002 14:52:39 +0930 (CST)
	(envelope-from darius@chowder.gsoft.com.au)
Received: (from darius@localhost)
	by chowder.gsoft.com.au (8.12.3/8.12.3/Submit) id g5D4gNtp003682;
	Thu, 13 Jun 2002 14:12:23 +0930 (CST)
Message-Id: <200206130442.g5D4gNtp003682@chowder.gsoft.com.au>
Date: Thu, 13 Jun 2002 14:12:23 +0930 (CST)
From: "Daniel O'Connor" <doconnor@gsoft.com.au>
Reply-To: "Daniel O'Connor" <doconnor@gsoft.com.au>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: cp returns non-zero when copying a symlink to it's linkee.
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         39217
>Category:       bin
>Synopsis:       cp returns non-zero when copying a symlink to it's linkee.
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jun 12 22:30:01 PDT 2002
>Closed-Date:    Sat Jul 06 02:19:15 PDT 2002
>Last-Modified:  Sat Jul 06 02:19:15 PDT 2002
>Originator:     Daniel O'Connor
>Release:        FreeBSD 4.6-PRERELEASE i386
>Organization:
>Environment:
System: FreeBSD chowder.gsoft.com.au 4.6-PRERELEASE FreeBSD 4.6-PRERELEASE #12: Fri May 10 15:54:54 CST 2002 darius@chowder.gsoft.com.au:/usr/obj/usr/src/sys/CHOWDER i386

>Description:
When cp is requested to copy a file to a link of that file (hard or soft) it
returns non-zero. This does seem a little contrary in my opinion.

>How-To-Repeat:
touch foo
ln -s foo bar
cp foo bar
echo $?

>Fix:

--- cp.c.orig   Thu Jun 13 14:11:27 2002
+++ cp.c        Thu Jun 13 14:11:37 2002
@@ -368,7 +368,7 @@
                            to_stat.st_ino == curr->fts_statp->st_ino) {
                                warnx("%s and %s are identical (not copied).",
                                    to.p_path, curr->fts_path);
-                               badcp = rval = 1;
+                               badcp = 1;
                                if (S_ISDIR(curr->fts_statp->st_mode))
                                        (void)fts_set(ftsp, curr, FTS_SKIP);
                                continue;

Seems to work, but I haven't tested it too much.

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: jon 
State-Changed-When: Sat Jul 6 02:15:04 PDT 2002 
State-Changed-Why:  

this is expected behavior.  As noted in the man page, "If cp detects an attempt to copy a file to itself, the copy will fail."  And failures are best detected by setting a non-zero exit status.  In any case, if cp didn't actually do any copying, it should return an error, much like trying to copy a nonexistant file will return an error. 

If you have a compelling reason why cp should return 0, let me know and I will reopen the PR. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=39217 
>Unformatted:
