Fix up-to-date repo databases being redownloaded when sandboxed

Signed-off-by: Remi Gacogne <rgacogne@archlinux.org>
Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Remi Gacogne 2024-05-29 17:33:32 +02:00 committed by Allan McRae
parent f0a7f85dbb
commit 24304c6df0
2 changed files with 17 additions and 7 deletions

View file

@ -413,14 +413,13 @@ static void curl_set_handle_opts(CURL *curl, struct dload_payload *payload)
curl_easy_setopt(curl, CURLOPT_USERAGENT, useragent);
}
if(!payload->force && payload->destfile_name &&
stat(payload->destfile_name, &st) == 0) {
if(!payload->force && payload->mtime_existing_file) {
/* start from scratch, but only download if our local is out of date. */
curl_easy_setopt(curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
curl_easy_setopt(curl, CURLOPT_TIMEVALUE, (long)st.st_mtime);
curl_easy_setopt(curl, CURLOPT_TIMEVALUE, payload->mtime_existing_file);
_alpm_log(handle, ALPM_LOG_DEBUG,
"%s: using time condition %ld\n",
payload->remote_name, (long)st.st_mtime);
payload->remote_name, (long)payload->mtime_existing_file);
} else if(stat(payload->tempfile_name, &st) == 0 && payload->allow_resume) {
/* a previous partial download exists, resume from end of file. */
payload->tempfile_openmode = "ab";
@ -1138,11 +1137,20 @@ static void prepare_resumable_downloads(alpm_list_t *payloads, const char *local
alpm_list_t *p;
for(p = payloads; p; p = p->next) {
struct dload_payload *payload = p->data;
if(payload->destfile_name) {
const char *destfilename = mbasename(payload->destfile_name);
char *dest = _alpm_get_fullpath(localpath, destfilename, "");
struct stat deststat;
if(stat(dest, &deststat) == 0 && deststat.st_size != 0) {
payload->mtime_existing_file = deststat.st_mtime;
}
FREE(dest);
}
if(!payload->tempfile_name) {
continue;
}
const char *filename = mbasename(payload->tempfile_name);
char *src = _alpm_get_fullpath(localpath, filename, "");;
char *src = _alpm_get_fullpath(localpath, filename, "");
struct stat st;
if(stat(src, &st) != 0 || st.st_size == 0) {
FREE(src);
@ -1249,7 +1257,7 @@ download_signature:
ret = updated ? 0 : 1;
}
if (finalize_download_locations(payloads, localpath) != 0) {
if (finalize_download_locations(payloads, localpath) != 0 && ret == 0) {
return -1;
}
return ret;

View file

@ -42,6 +42,8 @@ struct dload_payload {
alpm_list_t *cache_servers;
alpm_list_t *servers;
long respcode;
/* the mtime of the existing version of this file, if there is one */
long mtime_existing_file;
off_t initial_size;
off_t max_size;
off_t prevprogress;