From owner-freebsd-current@FreeBSD.ORG Fri Nov 18 18:36:45 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 D6D8D16A41F for ; Fri, 18 Nov 2005 18:36:45 +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 6ABF243D45 for ; Fri, 18 Nov 2005 18:36:45 +0000 (GMT) (envelope-from b.candler@pobox.com) Received: from thorn (localhost [127.0.0.1]) by thorn.pobox.com (Postfix) with ESMTP id 3A9D42FA; Fri, 18 Nov 2005 13:37:06 -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 F02A2589; Fri, 18 Nov 2005 13:37:04 -0500 (EST) Received: from brian by mappit.local.linnet.org with local (Exim 4.54 (FreeBSD)) id 1EdB6H-0003Jy-H3; Fri, 18 Nov 2005 18:36:41 +0000 Date: Fri, 18 Nov 2005 18:36:41 +0000 From: Brian Candler To: Eric Anderson Message-ID: <20051118183641.GA12669@uk.tiscali.com> References: <20051116161540.GB4383@uk.tiscali.com> <20051118091333.GA1058@galgenberg.net> <20051118145051.GA3713@Pandora.MHoerich.de> <20051118153616.GA12210@uk.tiscali.com> <437DF717.8010207@centtech.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <437DF717.8010207@centtech.com> 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: Fri, 18 Nov 2005 18:36:46 -0000 On Fri, Nov 18, 2005 at 09:45:27AM -0600, Eric Anderson wrote: > Brian Candler wrote: > >>This just adds a -o flag to cp, which preserves order. > > > > > >Hmm, that's another solution that I hadn't thought of. > > > >Advantages: simple to implement. (Even simpler if you use the ?: operator). > > > >Disadvantages: it's still strange that the default behaviour is to copy the > >files in an arbitary shuffled order. The manpage will need updating to > >document the -o flag, and hence will have to explain the strangeness. > >Commands arguably have too many flags already. > > I didn't think cp (or any tool, like tar) did it 'arbitrarily', but in > order of mtime. Is that not true? No, it's not true, for cp anyway. As far as I can tell, cp indirectly calls qsort() on the source items, using its own mastercmp() function to compare them. The only comparison it does is whether each item is a file or a directory. qsort() is not a stable sort, so even if all items compare equal, it has a habit of shuffling them around. brian@mappit brian$ cat x.c #include #include static int foo(const void *a, const void *b) { return 0; } #define NMEM 7 int main(void) { int a[NMEM] = {1,2,3,4,5,6,7}; int i; for (i=0; i