1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-08-13 17:03:46 -04:00

dload: add open_mode to payload struct

This is a precursor to a following patch which will move the setting of
options to a separate function. With the open mode as part of the
struct, we can avoid modifying stack allocated variables.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dave Reisner 2011-08-19 13:42:53 -04:00 committed by Dan McGee
parent 592ed13bce
commit d64c409913
2 changed files with 6 additions and 4 deletions

View File

@ -182,7 +182,6 @@ static int curl_download_internal(struct dload_payload *payload,
int ret = -1;
FILE *localf = NULL;
const char *useragent;
const char *open_mode = "wb";
char *effective_url;
/* RFC1123 states applications should support this length */
char hostname[256];
@ -195,6 +194,7 @@ static int curl_download_internal(struct dload_payload *payload,
alpm_handle_t *handle = payload->handle;
handle->pm_errno = 0;
payload->tempfile_openmode = "wb";
if(!payload->remote_name) {
payload->remote_name = get_filename(payload->fileurl);
}
@ -220,7 +220,8 @@ static int curl_download_internal(struct dload_payload *payload,
/* create a random filename, which is opened with O_EXCL */
snprintf(randpath, PATH_MAX, "%salpmtmp.XXXXXX", localpath);
if((fd = mkstemp(randpath)) == -1 || !(localf = fdopen(fd, open_mode))) {
if((fd = mkstemp(randpath)) == -1 ||
!(localf = fdopen(fd, payload->tempfile_openmode))) {
unlink(randpath);
close(fd);
_alpm_log(handle, ALPM_LOG_ERROR,
@ -267,14 +268,14 @@ static int curl_download_internal(struct dload_payload *payload,
curl_easy_setopt(handle->curl, CURLOPT_TIMEVALUE, (long)st.st_mtime);
} else if(stat(payload->tempfile_name, &st) == 0 && payload->allow_resume) {
/* a previous partial download exists, resume from end of file. */
open_mode = "ab";
payload->tempfile_openmode = "ab";
curl_easy_setopt(handle->curl, CURLOPT_RESUME_FROM, (long)st.st_size);
_alpm_log(handle, ALPM_LOG_DEBUG, "tempfile found, attempting continuation\n");
payload->initial_size = (double)st.st_size;
}
if(localf == NULL) {
localf = fopen(payload->tempfile_name, open_mode);
localf = fopen(payload->tempfile_name, payload->tempfile_openmode);
if(localf == NULL) {
goto cleanup;
}

View File

@ -28,6 +28,7 @@
struct dload_payload {
alpm_handle_t *handle;
const char *remote_name;
const char *tempfile_openmode;
char *tempfile_name;
char *destfile_name;
char *content_disp_name;