From owner-p4-projects@FreeBSD.ORG Wed Apr 14 15:01:00 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 15ED010656B2; Wed, 14 Apr 2010 15:01:00 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C7F551065698; Wed, 14 Apr 2010 15:00:59 +0000 (UTC) (envelope-from kientzle@freebsd.org) Received: from monday.kientzle.com (kientzle.com [66.166.149.50]) by mx1.freebsd.org (Postfix) with ESMTP id 922238FC17; Wed, 14 Apr 2010 15:00:59 +0000 (UTC) Received: (from root@localhost) by monday.kientzle.com (8.14.3/8.14.3) id o3EF19G3045713; Wed, 14 Apr 2010 15:01:09 GMT (envelope-from kientzle@freebsd.org) Received: from horton.x.kientzle.com (fw2.kientzle.com [10.123.1.2]) by kientzle.com with SMTP id vwwneqihqdppu2a8mrugsyk9fa; Wed, 14 Apr 2010 15:01:08 +0000 (UTC) (envelope-from kientzle@freebsd.org) Message-ID: <4BC5D8A5.7000004@freebsd.org> Date: Wed, 14 Apr 2010 08:00:53 -0700 From: Tim Kientzle User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.8.1.23) Gecko/20100314 SeaMonkey/1.1.18 MIME-Version: 1.0 To: Garrett Cooper References: <201004121230.o3CCUsIX029146@repoman.freebsd.org> <4BC3EB5B.5070801@freebsd.org> <4BC53714.80805@freebsd.org> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: David Forsythe , Perforce Change Reviews , Florent Thoumie Subject: Re: PERFORCE change 176831 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Apr 2010 15:01:00 -0000 Garrett Cooper wrote: > > To prevent race conditions [with regular files only], I should use > open(2). For all other files I would use the standard extract method > (so I don't get too fancy?). It seems like the file creation times > should be sufficiently fast with other file types that this kind of > behavior of open(2), blah wouldn't be required. No. This is only for a file that you're going to extract to disk and then turn around and read back again immediately. Rather than asking extract() to handle it and then opening it again yourself, you should open the file yourself, ask libarchive to write to the fd, then you can rewind and use the fd without reopening the file. Mostly, this is a small performance optimization since you avoid the close and re-open syscalls. Depending on the situation, it can also be a security improvement (it eliminates the window between libarchive closing the file and you re-opening it in which someone could conceivably replace the file with something else). The standard extract method is recommended if you're just pushing something out to disk, whether it's a regular file or a block device or hardlink. Libarchive knows a lot more about creating objects on disk than you want to teach pkg_install. As I said, this is just for the case where you want to pull something out of an archive into a file that you're going to immediately read back again. Tim