From james@jrv.org  Wed Apr 22 07:57:57 2009
Return-Path: <james@jrv.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id B959A106564A
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 22 Apr 2009 07:57:57 +0000 (UTC)
	(envelope-from james@jrv.org)
Received: from mail.jrv.org (adsl-70-243-84-13.dsl.austtx.swbell.net [70.243.84.13])
	by mx1.freebsd.org (Postfix) with ESMTP id 77CCB8FC15
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 22 Apr 2009 07:57:57 +0000 (UTC)
	(envelope-from james@jrv.org)
Received: from bigtex.housenet.jrv (localhost [127.0.0.1])
	by mail.jrv.org (8.14.3/8.14.3) with ESMTP id n3M7vi2l029089
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 22 Apr 2009 02:57:44 -0500 (CDT)
	(envelope-from james@bigtex.housenet.jrv)
Received: (from james@localhost)
	by bigtex.housenet.jrv (8.14.3/8.14.3/Submit) id n3M7vi1H029088;
	Wed, 22 Apr 2009 02:57:44 -0500 (CDT)
	(envelope-from james)
Message-Id: <200904220757.n3M7vi1H029088@bigtex.housenet.jrv>
Date: Wed, 22 Apr 2009 02:57:44 -0500 (CDT)
From: james@jrv.org
Reply-To: james@jrv.org
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: cp(1) wrongly reports errors in vacuous copy
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         133907
>Category:       bin
>Synopsis:       [patch] cp(1) wrongly reports errors in vacuous copy
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    jh
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Apr 22 08:00:02 UTC 2009
>Closed-Date:    Sun Mar 28 14:27:21 UTC 2010
>Last-Modified:  Sun Mar 28 14:27:21 UTC 2010
>Originator:     James R. Van Artsdalen
>Release:        FreeBSD 8.0-CURRENT amd64
>Organization:
>Environment:
System: FreeBSD bigtex.housenet.jrv 8.0-CURRENT FreeBSD 8.0-CURRENT #0 r189099: Fri Feb 27 07:09:47 CST 2009 james@bigtex.housenet.jrv:/usr/obj/usr/src/sys/GENERIC amd64


	

8.0-current svn r189099 amd64

	<precise description of the problem (multiple lines)>
>Description:
>How-To-Repeat:

$ mkdir x y
$ cp -Rp x/ y
cp: utimes: y/x: No such file or directory
cp: chown: y/x: No such file or directory
cp: chmod: y/x: No such file or directory
cp: chflags: y/x: No such file or directory
$ 

Appears to affect only the vacuous case of arg x being an empty directory, and only if -p is used.

This error is seen in diskless boots in /etc/rc.initdiskless during boot.

>Fix:

	

>Release-Note:
>Audit-Trail:

From: Jaakko Heinonen <jh@saunalahti.fi>
To: james@jrv.org
Cc: bug-followup@FreeBSD.org
Subject: Re: bin/133907: cp(1) wrongly reports errors in vacuous copy
Date: Mon, 4 May 2009 22:21:38 +0300

 Hi,
 
 On 2009-04-22, james@jrv.org wrote:
 > $ mkdir x y
 > $ cp -Rp x/ y
 > cp: utimes: y/x: No such file or directory
 > cp: chown: y/x: No such file or directory
 > cp: chmod: y/x: No such file or directory
 > cp: chflags: y/x: No such file or directory
 > $ 
 > 
 > Appears to affect only the vacuous case of arg x being an empty
 > directory, and only if -p is used.
 
 The problem is that in empty directory case fts(3) returns the path name
 without trailing slash in post-order phase. This results an incorrect
 value for "base".
 
 It's somewhat unexpected that fts(3) returns with different path name in
 post-order because the fts(3) manual page states:
 
   FTS_DP       A directory being visited in post-order.  The
 	       contents of the FTSENT structure will be
 	       unchanged from when it was returned in pre-
 	       order, i.e., with the fts_info field set to
 	       FTS_D.
 
 This happens only with FTS_NOCHDIR option used by cp(1).
 
 However there is actually no need to set the base value in post-order
 phase. This patch should fix the problem.
 
 --- patch begins here ---
 Index: bin/cp/cp.c
 ===================================================================
 --- bin/cp/cp.c	(revision 191680)
 +++ bin/cp/cp.c	(working copy)
 @@ -316,7 +316,8 @@ copy(char *argv[], enum op type, int fts
  			 * Since the first level MUST be FTS_ROOTLEVEL, base
  			 * is always initialized.
  			 */
 -			if (curr->fts_level == FTS_ROOTLEVEL) {
 +			if (curr->fts_level == FTS_ROOTLEVEL &&
 +			    curr->fts_info != FTS_DP) {
  				if (type != DIR_TO_DNE) {
  					p = strrchr(curr->fts_path, '/');
  					base = (p == NULL) ? 0 :
 --- patch ends here ---
 
 The fts(3) problem may be worth of fixing but I think that the cp(1)
 change is justified because the fts(3) (mis)behavior seems to exist on
 other OSes too.
 
 -- 
 Jaakko

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/133907: commit references a PR
Date: Thu, 26 Nov 2009 19:11:56 +0000 (UTC)

 Author: jh
 Date: Thu Nov 26 19:11:44 2009
 New Revision: 199844
 URL: http://svn.freebsd.org/changeset/base/199844
 
 Log:
   Reset path name back to original correctly in fts_build() when
   FTS_NOCHDIR option is used. fts_build() could strip a trailing slash
   from path name in post-order visit if a path pointing to an empty
   directory was given for fts_open().
   
   PR:		bin/133907, kern/134513
   Reviewed by:	das
   Approved by:	trasz (mentor)
   MFC after:	1 month
 
 Modified:
   head/lib/libc/gen/fts.c
 
 Modified: head/lib/libc/gen/fts.c
 ==============================================================================
 --- head/lib/libc/gen/fts.c	Thu Nov 26 19:09:10 2009	(r199843)
 +++ head/lib/libc/gen/fts.c	Thu Nov 26 19:11:44 2009	(r199844)
 @@ -842,11 +842,8 @@ mem1:				saved_errno = errno;
  	 * If not changing directories, reset the path back to original
  	 * state.
  	 */
 -	if (ISSET(FTS_NOCHDIR)) {
 -		if (len == sp->fts_pathlen || nitems == 0)
 -			--cp;
 -		*cp = '\0';
 -	}
 +	if (ISSET(FTS_NOCHDIR))
 +		sp->fts_path[cur->fts_pathlen] = '\0';
  
  	/*
  	 * If descended after called from fts_children or after called from
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: jh 
State-Changed-When: Thu Nov 26 19:55:21 UTC 2009 
State-Changed-Why:  
fts(3) patched in head (r199844). 


Responsible-Changed-From-To: freebsd-bugs->jh 
Responsible-Changed-By: jh 
Responsible-Changed-When: Thu Nov 26 19:55:21 UTC 2009 
Responsible-Changed-Why:  
Take. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=133907 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/133907: commit references a PR
Date: Wed, 30 Dec 2009 17:22:19 +0000 (UTC)

 Author: jh
 Date: Wed Dec 30 17:22:00 2009
 New Revision: 201263
 URL: http://svn.freebsd.org/changeset/base/201263
 
 Log:
   MFC r199844:
   
   Reset path name back to original correctly in fts_build() when
   FTS_NOCHDIR option is used. fts_build() could strip a trailing slash
   from path name in post-order visit if a path pointing to an empty
   directory was given for fts_open().
   
   PR:		bin/133907, kern/134513
   Approved by:	trasz (mentor)
 
 Modified:
   stable/8/lib/libc/gen/fts.c
 Directory Properties:
   stable/8/lib/libc/   (props changed)
   stable/8/lib/libc/stdtime/   (props changed)
 
 Modified: stable/8/lib/libc/gen/fts.c
 ==============================================================================
 --- stable/8/lib/libc/gen/fts.c	Wed Dec 30 17:16:49 2009	(r201262)
 +++ stable/8/lib/libc/gen/fts.c	Wed Dec 30 17:22:00 2009	(r201263)
 @@ -836,11 +836,8 @@ mem1:				saved_errno = errno;
  	 * If not changing directories, reset the path back to original
  	 * state.
  	 */
 -	if (ISSET(FTS_NOCHDIR)) {
 -		if (len == sp->fts_pathlen || nitems == 0)
 -			--cp;
 -		*cp = '\0';
 -	}
 +	if (ISSET(FTS_NOCHDIR))
 +		sp->fts_path[cur->fts_pathlen] = '\0';
  
  	/*
  	 * If descended after called from fts_children or after called from
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: jh 
State-Changed-When: Sun Mar 28 14:27:20 UTC 2010 
State-Changed-Why:  
Fixed in head and stable/8. 

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