From root@cstone.net  Tue Mar 14 22:38:31 2000
Return-Path: <root@cstone.net>
Received: from Astrovan.cstone.net (mailstop.cstone.net [205.197.102.13])
	by hub.freebsd.org (Postfix) with ESMTP id 14D1E37B99B
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 14 Mar 2000 22:38:30 -0800 (PST)
	(envelope-from root@cstone.net)
Received: from newbie.cho.cstone.net ([209.145.64.15])
          by Astrovan.cstone.net (Post.Office MTA v3.5.3 release 223
          ID# 0-59789U13500L1350S0V35) with ESMTP id net
          for <FreeBSD-gnats-submit@freebsd.org>;
          Wed, 15 Mar 2000 01:33:33 -0500
Received: (from root@localhost)
	by newbie.cho.cstone.net (8.9.3/8.9.3) id BAA05794;
	Wed, 15 Mar 2000 01:38:27 -0500 (EST)
	(envelope-from root@mail.cstone.net)
Message-Id: <200003150638.BAA05794@newbie.cho.cstone.net>
Date: Wed, 15 Mar 2000 01:38:27 -0500 (EST)
From: adrian@ubergeeks.com
Sender: root@cstone.net
Reply-To: adrian@ubergeeks.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: pkg_create copy_file() use of cp(1) and flags problems
X-Send-Pr-Version: 3.2

>Number:         17386
>Category:       bin
>Synopsis:       schg flag causes pkg_create cleaup problems
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    sheldonh
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Mar 14 22:40:02 PST 2000
>Closed-Date:    Wed Mar 15 01:36:44 PST 2000
>Last-Modified:  Wed Mar 15 01:37:13 PST 2000
>Originator:     Adrian Filipi-Martin
>Release:        FreeBSD 3.4-RELEASE i386
>Organization:
Ubergeeks Consulting
>Environment:

	3.4-RELEASE w/ports from 03/12/00.

>Description:

	If extended file flags are set on the mtree files in /etc/mtree,
	pkg_create cannot remove its temp files, because of how pkg_create 
	copies the mtree file to /var/tmp.  It exec's cp(1) with '-p' 
	which preserves the flags as well as the usual file metadata.

	Since the only files that are copied in this way are the pkg
	metadata files, e.g. +COMMENT, +DESCR, etc., it is of no great
	loss that the timestamps are not preserved in the created pacakge.
	It is a bother when pkg_create leaves garbage in /var/tmp that may
	not be easily removed.  The preservation of the flags is lost in
	pkg since tarfiles cannot handle the file flags.

	FYI, This bug was actually encountered when running "make package"
	for the gmake port.

>How-To-Repeat:

	# sh
	# cd /tmp
	# for i in DESCR COMMENT PLIST FOO; do echo FOO > $i; done
	# chflags schg /etc/mtree/BSD.local.dist
	# pkg_create -c COMMENT -d DESCR -f PLIST -p /tmp \
		-m /etc/mtree/BSD.local.dist PKG.tgz
	rm: /var/tmp/instmp.Xk5440/+MTREE_DIRS: Operation not permitted
	rm: /var/tmp/instmp.Xk5440: Directory not empty
	pkg_create: couldn't remove temporary dir '/var/tmp/instmp.Xk5440'
	# ls -lo /var/tmp/instmp.go5393 
	total 5
	-r--r--r--  1 root  wheel  schg 4112 Dec 20 00:53 +MTREE_DIRS


>Fix:
	
	Apply the following patch to usr.sbin/pkg_install/lib/file.c.  Note,
	'-r' was replaced with '-R' per the cp(1) manpage's recommendatons.
	Since no recurssive copies were actually found in the code, it may
	be possible to remove '-R' altogether.

--- file.c.orig	Wed Mar 15 00:50:24 2000
+++ file.c	Wed Mar 15 00:57:57 2000
@@ -412,9 +412,9 @@
     char cmd[FILENAME_MAX];
 
     if (fname[0] == '/')
-	snprintf(cmd, FILENAME_MAX, "cp -p -r %s %s", fname, to);
+	snprintf(cmd, FILENAME_MAX, "cp -R %s %s", fname, to);
     else
-	snprintf(cmd, FILENAME_MAX, "cp -p -r %s/%s %s", dir, fname, to);
+	snprintf(cmd, FILENAME_MAX, "cp -R %s/%s %s", dir, fname, to);
     if (vsystem(cmd)) {
 	cleanup(0);
 	errx(2, "could not perform '%s'", cmd);


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->sheldonh 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Wed Mar 15 01:10:13 PST 2000 
Responsible-Changed-Why:  
This has been fixed in NetBSD since Nov 1999.  I'll take this one. 
State-Changed-From-To: open->closed 
State-Changed-By: sheldonh 
State-Changed-When: Wed Mar 15 01:36:44 PST 2000 
State-Changed-Why:  
Committed as rev 1.41, thanks! 
Also merged onto the RELENG_4 and RELENG_3 branches. 
>Unformatted:
