[BusyBox] mv is deleting files!
Jim Bauer
jfbauer at nfr.com
Thu Jul 14 15:21:30 UTC 2005
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)
> b) the copy may fail for "other reasons"
>
More information about the busybox
mailing list