incorrect cp(1) behaviour upon "mkdir foo; cp -r foo foo"
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
coreutils |
Confirmed
|
Undecided
|
Unassigned | ||
coreutils (Ubuntu) |
Triaged
|
Wishlist
|
Unassigned |
Bug Description
Binary package hint: coreutils
GNU coreutils cp(1) behaves incorrectly if the user tries to copy a directory recursively. It (rightly) prints an error message, BUT copies the directory anyway, at least one level deep. To demonstrate:
| ropers@
| Linux tranquility 2.6.22-14-386 #1 Sun Oct 14 22:36:54 GMT 2007 i686 GNU/Linux
We're using Ubuntu "Gutsy Gibbon" 7.10.
| ropers@
| ropers@
We're creating a folder containing one file.
| ropers@
| cp: cannot copy a directory, `foo', into itself, `foo/foo'
We're trying to copy that folde into itself. cp(1) prints an error (as it should). However, ls -al (ll) shows that despite the error message, foo and the testfile it contains have nevertheless been copied into foo:
| ropers@
| 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
| ropers@
| 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
| ropers@
This should not happen. When asked to copy a directory recursively, cp(1) should print an error and not perform any copy operation at all.
My understanding is the behaviour is correct: when 'cp' is copying to a directory, it will copy *under* the target directory, not *over* it. So it will start the copy and later it will notice it is copying recursively -- and immediately stop.
Nevertheless, I am open to suggestions ;-)