[Toybox] [Patches] - Some more static analysis fixes

Rob Landley rob at landley.net
Mon Oct 13 21:56:08 PDT 2014


On 10/12/14 22:39, Ashwini Sharma wrote:
> Hi Rob,
> 
> --- cp.c.patch:
> 
> Why this change?
> 
> -    if (CFG_CP_MV && toys.which->name[0] == 'm') rc = rename(src,
> TT.destname);
> +    if (CFG_CP_MV && toys.which->name[0] == 'm' && (toys.optflags &
> FLAG_f))
> +      rc = rename(src, TT.destname);
> 
> $ strace mv umount umount.old 2>&1 | grep rename
> rename("umount", "umount.old")          = 0
> 
> in case of mv __rename()__ is tried at first. The issue handled is in
> case when user
> gives option __-i__

$ mv -i out blah

Did not prompt. Only does so if destination exists...?

Ah, I see. When overwriting, mv -i does not prompt for the top level
file listed on the command line.

> thats why this extra check for mv. 

But that's not what this is doing.

The above will only attempt a rename if the user passes the option -f.
That is the only instance of rename() in the program. So the effect of
the "fix" was to disable rename() entirely and always use the
copy-and-delete codepath for everything.

Ah, I see: mv isn't doing -f right either, because it only falls back to
the copy version when errno is EXDEV, not because it couldn't write to
the destination and -f needs to remove it and try again. Except rename
does oerwrite, so it needs to check first... hmmm...

I'll fiddle with it.

> regards,
> Ashwini

Thanks for the bug report,

Rob

 1413262568.0


More information about the Toybox mailing list