Hi folks!
Sometimes I experience very unpleasant behavior of wget (using some not-really-recent CVS version of wget 1.9, under W98SE). I have a partially downloaded file (usually a big one, there is not so big probability of interrupted download of a small file), so I want to finish the download (later, not within the same wget run) using something like
wget -c http://www.example.com/foo
After some time, I try to check the progress and, to my shock, I find that the file is being downloaded from start (so that the previously downloaded data is lost).
I was able to reproduce the problem (I hope it is the same problem, the original problem occurs very rarely): When wget -c is issued and the first connection attempt fails, in further attempts, wget does not even send Range header!
I have tried to track down the problem, and I have found one suspect (although I am not really familiar with the source, so this may not be correct):
In http_loop() (in http.c), there is code like the following:
/* Decide whether or not to restart. */ hstat.restval = 0; if (count > 1) hstat.restval = hstat.len; /* continue where we left off */ else if (opt.always_rest && stat (locf, &st) == 0 && S_ISREG (st.st_mode)) hstat.restval = st.st_size;
During the second attempt, hstat.len is still zero if the first connection attempt failed. But as count>1, we use that zero to initialize hstat.restval. (And, as a probably mistaken idea, in gethttp(), the file open mode is selected using hs->restval ? "ab" : "wb", so that even when opt.always_rest is set, this command is able to rewrite the file. It could be a good idea to at least assert that we are not overwriting the file if opt.always_rest is set.)
With regards, Petr Kadlec
-- Don't whisper/Don't talk/Don't run if you can walk -- U2 -- Petr Kadlec <[EMAIL PROTECTED]> ICQ #68196926, http://mormegil.wz.cz/