Re: Order of files with 'cp'

From: Brian Candler <B.Candler_at_pobox.com>
Date: Mon, 21 Nov 2005 12:38:51 +0000
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.
Received on Mon Nov 21 2005 - 11:39:07 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:48 UTC