busybox cp vs gnu cp

Ming-Ching Tiew mctiew at yahoo.com
Wed Sep 17 02:01:43 UTC 2008




--- On Tue, 9/16/08, Denys Vlasenko <vda.linux at googlemail.com> wrote:

> From: Denys Vlasenko <vda.linux at googlemail.com>
> Subject: Re: busybox cp vs gnu cp
> To: busybox at busybox.net, mctiew at yahoo.com
> Date: Tuesday, September 16, 2008, 9:58 PM
> 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?
> 

Dangerous or not it all depends on your intent.

I think the current busybox behavior is more dangerous,
because it wipes out the symbolic link and created
a separate copy of the file without the user
realizing it.

Coreutils cp existed first, and it's behaviour has 
been accepted as defacto. Busybox cp comes into 
the picture to "resemble" coreutils cp, and yet 
there are differences in behaviour. That will break 
their way of thinking or if they already have code, 
that will break their code.

> 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.
> 

It's all in the mind about what's considered
the accepted "intention" or "behaviour".

Cheers


      



More information about the busybox mailing list