mirror of
https://github.com/moparisthebest/pacman
synced 2024-11-11 20:05:07 -05:00
dload: add 'unlink_on_fail' to payload struct
Let callers of _alpm_download state whether we should delete on fail, rather than inferring it from context. We still override this decision and always unlink when a temp file is used. Signed-off-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
2ca27ab3a1
commit
24824b54ce
@ -197,6 +197,7 @@ int SYMEXPORT alpm_db_update(int force, alpm_db_t *db)
|
|||||||
snprintf(payload->fileurl, len, "%s/%s.db", server, db->treename);
|
snprintf(payload->fileurl, len, "%s/%s.db", server, db->treename);
|
||||||
payload->handle = handle;
|
payload->handle = handle;
|
||||||
payload->force = force;
|
payload->force = force;
|
||||||
|
payload->unlink_on_fail = 1;
|
||||||
|
|
||||||
ret = _alpm_download(payload, syncpath, NULL);
|
ret = _alpm_download(payload, syncpath, NULL);
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@ static size_t parse_headers(void *ptr, size_t size, size_t nmemb, void *user)
|
|||||||
static int curl_download_internal(struct dload_payload *payload,
|
static int curl_download_internal(struct dload_payload *payload,
|
||||||
const char *localpath, char **final_file)
|
const char *localpath, char **final_file)
|
||||||
{
|
{
|
||||||
int ret = -1, should_unlink = !payload->allow_resume;
|
int ret = -1;
|
||||||
FILE *localf = NULL;
|
FILE *localf = NULL;
|
||||||
const char *useragent;
|
const char *useragent;
|
||||||
const char *open_mode = "wb";
|
const char *open_mode = "wb";
|
||||||
@ -217,7 +217,7 @@ static int curl_download_internal(struct dload_payload *payload,
|
|||||||
|
|
||||||
/* we can't support resuming this kind of download, so a partial transfer
|
/* we can't support resuming this kind of download, so a partial transfer
|
||||||
* will be destroyed */
|
* will be destroyed */
|
||||||
should_unlink = 1;
|
payload->unlink_on_fail = 1;
|
||||||
|
|
||||||
/* create a random filename, which is opened with O_EXCL */
|
/* create a random filename, which is opened with O_EXCL */
|
||||||
snprintf(randpath, PATH_MAX, "%salpmtmp.XXXXXX", localpath);
|
snprintf(randpath, PATH_MAX, "%salpmtmp.XXXXXX", localpath);
|
||||||
@ -312,8 +312,6 @@ static int curl_download_internal(struct dload_payload *payload,
|
|||||||
break;
|
break;
|
||||||
case CURLE_ABORTED_BY_CALLBACK:
|
case CURLE_ABORTED_BY_CALLBACK:
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
case CURLE_OPERATION_TIMEDOUT:
|
|
||||||
/* fallthrough */
|
|
||||||
default:
|
default:
|
||||||
if(!payload->errors_ok) {
|
if(!payload->errors_ok) {
|
||||||
handle->pm_errno = ALPM_ERR_LIBCURL;
|
handle->pm_errno = ALPM_ERR_LIBCURL;
|
||||||
@ -396,7 +394,7 @@ cleanup:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if((ret == -1 || dload_interrupted) && should_unlink && tempfile) {
|
if((ret == -1 || dload_interrupted) && payload->unlink_on_fail && tempfile) {
|
||||||
unlink(tempfile);
|
unlink(tempfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ struct dload_payload {
|
|||||||
int force;
|
int force;
|
||||||
int allow_resume;
|
int allow_resume;
|
||||||
int errors_ok;
|
int errors_ok;
|
||||||
|
int unlink_on_fail;
|
||||||
};
|
};
|
||||||
|
|
||||||
void _alpm_dload_payload_free(struct dload_payload *payload);
|
void _alpm_dload_payload_free(struct dload_payload *payload);
|
||||||
|
Loading…
Reference in New Issue
Block a user