[BusyBox] mv is deleting files!

Rainer Weikusat rainer.weikusat at sncag.com
Thu Jul 14 17:11:46 UTC 2005


Jim Bauer <jfbauer at nfr.com> writes:
> On Thursday 14 July 2005 10:10, Rainer Weikusat wrote:
>> cp_mv_stat returns -1 in case of an error, 3 if the stat'et path name
>> was a directory, 1 if it existed and was not a directory and 0 if
>> the stat failed with errno set to ENOENT. The unlink gets execute
>> if the cp_mv_stat-return value is 0 or greater. A quick fix would
>> be change the
>> 
>>         if (unlink(dest) < 0)
>> 
>> to
>> 
>>         if (source_exists && unlink(dest) < 0)
>> 
>> but IMHO this is still wrong, because
>> 
>>         a) source may go away before it is copied and after
>>            dest is removed
>
> Why not (with a bit more error checking)...
>
> sfd = open(source_file,...)
> if (sfd == -1)
>   goto err
> unlink(dest)
> dfd = open(dest, ...)
> copy(sfd, dfd)

Code it -- use it. I won't.



More information about the busybox mailing list