Order of files with 'cp'

Brian Candler B.Candler at pobox.com
Sun Nov 20 12:50:31 PST 2005


On Sun, Nov 20, 2005 at 12:27:06PM -0800, Tim Kientzle wrote:
> >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'.
> 
> Why is that an optimization?

I'm only regurgitating what is written in /usr/src/bin/cp/cp.c:

/*
 * mastercmp --
 *      The comparison function for the copy order.  The order is to copy
 *      non-directory files before directory files.  The reason for this
 *      is because files tend to be in the same cylinder group as their
 *      parent directory, whereas directories tend not to be.  Copying the
 *      files first reduces seeking.
 */

> I thought the whole point of this thread was that users
> expect utilities to process the command-line arguments
> in the order they're given.

That wasn't the point I made at the start of the thread - somebody else
brought up POLA - although I would be happy for cp to process command-line
arguments strictly in the order they are given (in which case, you just
replace mastercmp with NULL when calling fts_open)

I suggested that if the above 'optimisation' makes sense, it should still be
possible to make cp copy arguments in the order given if they are all files
or all directories. I gave some suggested ways of achieving this.

Regards,

Brian.


More information about the freebsd-current mailing list