On 19/10/2007, Andreas Kahari <[EMAIL PROTECTED]> wrote: > On 19/10/2007, ropers <[EMAIL PROTECTED]> wrote: > > > > IMHO cp behaving like this is somewhat nicer than its current > > behaviour on apparently most or all BSD OSes. Then again, I STILL > > can't code, so I've no right to complain. ;o) > > > > Really? It is complaining that it can't move foo into itself, and does > it anyway (hint: have a look inside foo after the operation)... > > Andreas
You're right! While the behaviour of OpenBSD cp(1) in this regard is maybe not perfect, it turns out that the behaviour of GNU coreutils cp(1) is MUCH, MUCH worse: | [EMAIL PROTECTED]:~$ uname -a | Linux tranquility 2.6.22-14-386 #1 Sun Oct 14 22:36:54 GMT 2007 i686 GNU/Linux back on the Linux box | [EMAIL PROTECTED]:~$ rm -rf foo and back to square one | [EMAIL PROTECTED]:~$ mkdir foo | [EMAIL PROTECTED]:~$ touch foo/testfile | [EMAIL PROTECTED]:~$ cp -r foo foo | cp: cannot copy a directory, `foo', into itself, `foo/foo' | [EMAIL PROTECTED]:~$ ll foo | total 12 | drwxr-xr-x 3 ropers ropers 4096 2007-10-19 22:57 ./ | drwxr-xr-x 85 ropers ropers 4096 2007-10-19 22:56 ../ | drwxr-xr-x 2 ropers ropers 4096 2007-10-19 22:57 foo/ | -rw-r--r-- 1 ropers ropers 0 2007-10-19 22:56 testfile | [EMAIL PROTECTED]:~$ ll foo/foo | total 8 | drwxr-xr-x 2 ropers ropers 4096 2007-10-19 22:57 ./ | drwxr-xr-x 3 ropers ropers 4096 2007-10-19 22:57 ../ | -rw-r--r-- 1 ropers ropers 0 2007-10-19 22:57 testfile | [EMAIL PROTECTED]:~$ Andreas was absolutely right: * BSD cp(1) starts the recursive copying and only fails when the name gets too long. * GNU cp(1) however tells us that it can't copy recursively, AND THEN DOES IT ANYWAY, at least for the initial subdirectory. So GNU cp(1) tells us one thing and does another. That is SO stupid, it boggles the mind. Yes, IMHO the optimal way would be to give an error message similar to the one GNU cp(1) spits out, AND to NOT perform any copy operation in such a case. Can I code this and submit diffs? No. So again, I had better STFU. But thanks to everybody who helped clearing this up, it's always good to learn. --ropers