From owner-freebsd-current@FreeBSD.ORG Sun Nov 20 19:43:03 2005 Return-Path: X-Original-To: freebsd-current@freebsd.org Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E4E5B16A41F; Sun, 20 Nov 2005 19:43:03 +0000 (GMT) (envelope-from b.candler@pobox.com) Received: from thorn.pobox.com (thorn.pobox.com [208.210.124.75]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8E51343D45; Sun, 20 Nov 2005 19:43:03 +0000 (GMT) (envelope-from b.candler@pobox.com) Received: from thorn (localhost [127.0.0.1]) by thorn.pobox.com (Postfix) with ESMTP id 5ACF271A; Sun, 20 Nov 2005 14:43:24 -0500 (EST) Received: from mappit.local.linnet.org (212-74-113-67.static.dsl.as9105.com [212.74.113.67]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by thorn.sasl.smtp.pobox.com (Postfix) with ESMTP id 2CBF680B; Sun, 20 Nov 2005 14:29:37 -0500 (EST) Received: from brian by mappit.local.linnet.org with local (Exim 4.54 (FreeBSD)) id 1EdusE-000568-53; Sun, 20 Nov 2005 19:29:14 +0000 Date: Sun, 20 Nov 2005 19:29:14 +0000 From: Brian Candler To: Tim Kientzle Message-ID: <20051120192914.GC19572@uk.tiscali.com> References: <20051116161540.GB4383@uk.tiscali.com> <437F7E22.5050800@freebsd.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <437F7E22.5050800@freebsd.org> User-Agent: Mutt/1.4.2.1i Cc: freebsd-current@freebsd.org Subject: Re: Order of files with 'cp' X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 20 Nov 2005 19:43:04 -0000 On Sat, Nov 19, 2005 at 11:33:54AM -0800, Tim Kientzle wrote: > Brian Candler wrote: > >I've noticed on FreeBSD-5.4 and -6.0 that the order in which 'cp' copies > >multiple files does not match the order they're given on the command line. > ... > >I've had a look through the code, and it seems that cp calls fts_open() > >with > >the list of files in argv; fts_open then does a qsort() on the arguments, > >using the comparison function mastercmp() provided by cp: > > My suggestion: Have 'cp' call fts_open once for each > command-line argument, instead of giving fts_open the entire > argv list to muck with. Erm, but that just undoes the reason for calling fts_open with mastercmp in the first place, which is to get it to pick files before directories (or vice versa, as its behaviour seems to be) as an 'optimisation'. If you are happy to drop that behaviour, then you might as well just call fts_open with NULL as the compare function. In that case it will process each element of argv in sequence anyway.