busybox cp vs gnu cp
Denys Vlasenko
vda.linux at googlemail.com
Tue Sep 16 21:58:31 UTC 2008
On Tuesday 16 September 2008 03:49, Ming-Ching Tiew wrote:
>
> Tried this with busybox :-
>
> # cp /etc/hosts /tmp/a
> # ln -s /tmp/a /tmp/b
> # cp /etc/passwd /tmp/b
>
> After this, /tmp/b which was a symbolic link has become a normal
> text file which content is /etc/passwd. File /tmp/a
> remaind unchanged.
>
> When I tried this with gnu 'cp' the end result
> is /tmp/b remain as a symbolic link, and /tmp/a was modified
> accordingly.
This is intended. Coreutils cp behavior is dangerous.
Just imagine that the user running this command wants this:
"copy /etc/hosts to /tmp/a, creating /tmp/a if it doesn't exist,
or overwrite if it exists. In other words, I don't care
whether it exists or not, I simpy want to make an exact
duplicate of /etc/hosts."
which is what English word "copy" implies, right?
If you really want "overwrite symlink destination" semantic,
why won't you do "cat /etc/hosts >/tmp/b"?
In such command, your intention would be much clearer.
--
vda
More information about the busybox
mailing list