Order of files with 'cp'

Brian Candler B.Candler at pobox.com
Sun Nov 20 11:43:04 PST 2005


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.


More information about the freebsd-current mailing list