[Toybox] [PATCH] Implement mv -n / cp -n (no clobber).

Andy Chu andychup at gmail.com
Mon Mar 21 00:03:30 PDT 2016


On Sun, Mar 20, 2016 at 8:57 PM, Rob Landley <rob at landley.net> wrote:
> On 03/19/2016 02:40 AM, Andy Chu wrote:
>> This fixes a failing test case in mv.test.
>
> There are actually three modes:
>
> -n will leave the existing file.
> -f will delete the existing file only if it can't write to it.
> --remove-destination will delete the existing file before trying to
> write to it.
>
> Alas, for installing, you want --remove-destination. Which is so very
> non-posix it doesn't even have a short option. cp -f will stomp a toybox
> or busybox binary so everything is bunzip2, and -n will leave the
> existing file (not install the new one).
>
> That's why this is still on my todo list, I wanted to have
> scripts/install.sh --force do --remove-destination, but can't assume the
> host's cp has it. I should just make it rm -f then cp -n in two commands...

Maybe I'm not understanding --remove-destination correctly, but does
this patch make it any harder to implmene it?

Even after reading the coreutils manual, I see understand a situation
where you would want to use  --remove-destination instead of --force.
I guess this is not the situation is applies in but I can't think of
another one.

$ ls -l
-rw-rw-r-- 1 andy andy 4 Mar 20 23:58 foo
-r--r--r-- 1 andy andy 5 Mar 20 23:58 hard
-r--r--r-- 1 andy andy 6 Mar 20 23:58 hard2

$ cp foo hard
cp: cannot create regular file ‘hard’: Permission denied
$ cp --force foo hard
$ cp --remove-destination foo hard2

The result seems the same either way ?  The destination is copied over.

Andy

 1458543810.0


More information about the Toybox mailing list