libalpm: prevent download error pages ending up in package files
Some servers respond with error pages (e.g. 404.html) when a package is not present. These were getting written to packages before moving onto the next server. Reset the download progress on 400+ error conditions to avoid this. Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
6f35ce1570
commit
3401f9e142
1 changed files with 10 additions and 0 deletions
|
@ -510,6 +510,16 @@ static int curl_check_finished_download(CURLM *curlm, CURLMsg *msg,
|
||||||
payload->remote_name, hostname, payload->error_buffer);
|
payload->remote_name, hostname, payload->error_buffer);
|
||||||
server_soft_error(handle, payload->fileurl);
|
server_soft_error(handle, payload->fileurl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fflush(payload->localf);
|
||||||
|
if(fstat(fileno(payload->localf), &st) == 0 && st.st_size != payload->initial_size) {
|
||||||
|
/* an html error page was written to the file, reset it */
|
||||||
|
if(ftruncate(fileno(payload->localf), payload->initial_size)) {
|
||||||
|
RET_ERR(handle, ALPM_ERR_SYSTEM, -1);
|
||||||
|
}
|
||||||
|
fseek(payload->localf, payload->initial_size, SEEK_SET);
|
||||||
|
}
|
||||||
|
|
||||||
if(curl_retry_next_server(curlm, curl, payload) == 0) {
|
if(curl_retry_next_server(curlm, curl, payload) == 0) {
|
||||||
(*active_downloads_num)++;
|
(*active_downloads_num)++;
|
||||||
return 2;
|
return 2;
|
||||||
|
|
Loading…
Add table
Reference in a new issue