A retry took its offset from stat(2) of the destination, which misses
buffered output and names the wrong file when a temporary file is in
use, so resumed data could land at the wrong offset and the result was
reported as complete. A retry answered with the whole document, as a
server does which ignores the range or no longer has the version asked
for with If-Range, was appended to what was there.
Keep the output file open across retries, resume from the bytes
written to it, and discard whatever the server does not resume. Start
over when libfetch reports FETCH_RESTART or a different entity tag.
Retry after a read error as well, such as a chunked body cut short or
a reset connection, which either failed outright or started the whole
file again. Retry only while an attempt gets further than the ones
before it, counted from where the first attempt started and no longer
from the size of a file that happened to be in the way; a new version
of the file gets one fresh start.
A file found at the destination and resumed in place is not discarded
when a retry is answered from before the point it was resumed at:
continue in a temporary file, or give up under -R, as for a file that
does not match on the first attempt. Remove a temporary file when the
transfer fails, also under -r and after a truncated transfer, unless
-R is given: nothing can resume it.
A -r run whose local mtime did not match the server's went on reading
the stream it had just closed when the server ignored the range or the
local file was empty; refetch in that case too.
Sponsored by: Rubicon Communications, LLC ("Netgate")