[pacman-dev] [PATCH 1/2] dload: reset payload filename members before download
To avoid conflicts on reusing a payload after a failed download, ensure that we reset the filename hints in the payload struct prior to the download operation. Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- lib/libalpm/dload.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index 0598806..b3ac024 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -390,6 +390,11 @@ static int curl_download_internal(struct dload_payload *payload, CURL *curl = get_libcurl_handle(handle); handle->pm_errno = 0; + /* make sure these are NULL */ + FREE(payload->tempfile_name); + FREE(payload->destfile_name); + FREE(payload->content_disp_name); + payload->tempfile_openmode = "wb"; if(!payload->remote_name) { STRDUP(payload->remote_name, get_filename(payload->fileurl), -- 1.7.9.4
In case we have a mirror failure, unlink_on_fail would remain set, causing an interrupt in a successive download attempt to be wrongly unlinked. This also fixes a memory leak in the url member, as we would allocate over the previous, unfreed URL. Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- lib/libalpm/sync.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index 69d27af..feab302 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -864,6 +864,9 @@ static int download_single_file(alpm_handle_t *handle, struct dload_payload *pay { const alpm_list_t *server; + payload->handle = handle; + payload->allow_resume = 1; + for(server = payload->servers; server; server = server->next) { const char *server_url = server->data; size_t len; @@ -872,12 +875,15 @@ static int download_single_file(alpm_handle_t *handle, struct dload_payload *pay len = strlen(server_url) + strlen(payload->remote_name) + 2; MALLOC(payload->fileurl, len, RET_ERR(handle, ALPM_ERR_MEMORY, -1)); snprintf(payload->fileurl, len, "%s/%s", server_url, payload->remote_name); - payload->handle = handle; - payload->allow_resume = 1; if(_alpm_download(payload, cachedir, NULL) != -1) { return 0; } + + /* we failed the download, clean out the URL and any bits that might be + * set in _alpm_download */ + payload->unlink_on_fail = 0; + free(payload->fileurl); } return -1; -- 1.7.9.4
participants (1)
-
Dave Reisner