From owner-freebsd-current@FreeBSD.ORG Fri Nov 18 14:50:57 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 C23EB16A41F for ; Fri, 18 Nov 2005 14:50:57 +0000 (GMT) (envelope-from m@MHoerich.de) Received: from mail.gmx.net (mail.gmx.net [213.165.64.20]) by mx1.FreeBSD.org (Postfix) with SMTP id CF29343D45 for ; Fri, 18 Nov 2005 14:50:56 +0000 (GMT) (envelope-from m@MHoerich.de) Received: (qmail invoked by alias); 18 Nov 2005 14:50:55 -0000 Received: from p548B6007.dip.t-dialin.net (EHLO localhost) [84.139.96.7] by mail.gmx.net (mp024) with SMTP; 18 Nov 2005 15:50:55 +0100 X-Authenticated: #5114400 Date: Fri, 18 Nov 2005 15:50:53 +0100 From: Mario Hoerich To: Brian Candler , freebsd-current@freebsd.org Message-ID: <20051118145051.GA3713@Pandora.MHoerich.de> Mail-Followup-To: Brian Candler , freebsd-current@freebsd.org References: <20051116161540.GB4383@uk.tiscali.com> <20051118091333.GA1058@galgenberg.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20051118091333.GA1058@galgenberg.net> User-Agent: Mutt/1.4.2.1i X-Y-GMX-Trusted: 0 Cc: 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 14:50:57 -0000 # Ulrich Spoerlein: > 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. > > This is noticeable when the target server is remote and/or slow (e.g. NFS; > > USB flash device). [...] > If it can be done without creating too much confusion in the code, I'm > all for it. Sadly I'm not familiar with the code ... That's pretty simple, actually. :) This just adds a -o flag to cp, which preserves order. diff -ur cp.orig/cp.1 cp/cp.1 --- cp.orig/cp.1 Fri Nov 18 15:48:22 2005 +++ cp/cp.1 Fri Nov 18 15:45:48 2005 @@ -153,6 +153,8 @@ or .Fl i options.) +.It Fl o +Preserve the order given on the command line. .It Fl p Cause .Nm diff -ur cp.orig/cp.c cp/cp.c --- cp.orig/cp.c Fri Nov 18 15:48:22 2005 +++ cp/cp.c Fri Nov 18 15:45:45 2005 @@ -83,7 +83,7 @@ PATH_T to = { to.p_path, emptystring, "" }; -int fflag, iflag, nflag, pflag, vflag; +int fflag, iflag, nflag, pflag, vflag, oflag; static int Rflag, rflag; volatile sig_atomic_t info; @@ -102,7 +102,7 @@ char *target; Hflag = Lflag = Pflag = 0; - while ((ch = getopt(argc, argv, "HLPRfinprv")) != -1) + while ((ch = getopt(argc, argv, "HLPRfinoprv")) != -1) switch (ch) { case 'H': Hflag = 1; @@ -131,6 +131,9 @@ nflag = 1; fflag = iflag = 0; break; + case 'o': + oflag = 1; + break; case 'p': pflag = 1; break; @@ -270,7 +273,12 @@ mask = ~umask(0777); umask(~mask); - if ((ftsp = fts_open(argv, fts_options, mastercmp)) == NULL) + if (oflag == 1) + ftsp = fts_open(argv, fts_options, NULL); + else + ftsp = fts_open(argv, fts_options, mastercmp); + + if (ftsp == NULL) err(1, "fts_open"); for (badcp = rval = 0; (curr = fts_read(ftsp)) != NULL; badcp = 0) { switch (curr->fts_info) { diff -ur cp.orig/utils.c cp/utils.c --- cp.orig/utils.c Fri Nov 18 15:48:22 2005 +++ cp/utils.c Fri Nov 18 15:45:40 2005 @@ -331,8 +331,8 @@ { (void)fprintf(stderr, "%s\n%s\n", -"usage: cp [-R [-H | -L | -P]] [-f | -i | -n] [-pv] source_file target_file", -" cp [-R [-H | -L | -P]] [-f | -i | -n] [-pv] source_file ... " +"usage: cp [-R [-H | -L | -P]] [-f | -i | -n] [-o] [-pv] source_file target_file", +" cp [-R [-H | -L | -P]] [-f | -i | -n] [-o] [-pv] source_file ... " "target_directory"); exit(EX_USAGE); } Regards, Mario