Order of files with 'cp'
Brian Candler
B.Candler at pobox.com
Mon Nov 21 04:39:07 PST 2005
On Mon, Nov 21, 2005 at 05:44:59PM +1100, Peter Jeremy wrote:
> Alternatively, make two passes through argv - on the first pass, copy
> all the directories, on the second pass, copy all the files.
Or vice versa :-)
The comment says it copies files before directories. However the
implementation of mastercmp() returns -1 when comparing directory A to
anything else B; therefore it sorts directories before files.
So at very least the comment needs changing. I agree that a real-world test
is the only way to settle the best behaviour definitively.
Also, remember that cp -R can work recursively to any depth. Handling argv[]
in two passes as you suggest only affects the first level. Now, perhaps when
copying subdirectories we care even less about preserving the 'natural'
order of files; but as has been pointed out elsewhere, it's quite likely
that we could have 10,000 files and not really want to go to the trouble of
sorting them, just to select the subsets of 'all directories' and 'all
non-directories'.
In this case, implementing the two-pass selection as an option within
fts_open makes sense.
Regards,
Brian.
More information about the freebsd-current
mailing list