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

Rob Landley rob at landley.net
Sun Mar 27 23:59:50 PDT 2016



On 03/27/2016 02:09 PM, Andy Chu wrote:
>>> Anecdotally, it seems like a lot of shell script issues are caused by
>>> unexpected existing state, but in a lot of cases you don't CARE about
>>> the existing state -- you just want a final state (e.g. a bunch of
>>> symlinks to toybox).
>>
>> "ln -sf" actually works pretty predictably. :)
> 
> One more nitpick ... ln -sf isn't idempotent for the same reason that
> cp isn't.  If you run it more than once you get different results.

You're right, I was missing the -n

> I was trying to create a package manager with sandboxed builds, with
> the aforementioned linux-user-chroot, and my own tools.  Bootstrapped
> all in shell.  All of my ln invocations used -T /
> --no-target-directory for this reason.  (At least this flag doesn't
> seem to be entangled with other behavior, unlike mkdir and rm).

I haven't looked up the difference beween -n and -T. I assume there is
one, but haven't dug into it yet because nobody's asked.

> $ mkdir foo
> 
> $ ln -sf foo link; tree --charset=ascii
> .
> |-- foo
> `-- link -> foo

I need to add --forest to toybox ps. It's on the todo list.

(In theory it should probably be "-o forest". And --forest would imply
adding -o forest -k forest.)

> $ ln -sf foo link; tree --charset=ascii
> .
> |-- foo
> |   `-- foo -> foo
> `-- link -> foo
> 
> Compare with:
> 
> $ mkdir foo
> 
> $ ln -sf -T foo link; tree --charset=ascii
> .
> |-- foo
> `-- link -> foo
> 
> $ ln -sf -T foo link; tree --charset=ascii
> .
> |-- foo
> `-- link -> foo

Yeah, -n does that too? Toybox implements -n.

Rob

 1459148390.0


More information about the Toybox mailing list