mirror of
https://github.com/moparisthebest/pacman
synced 2025-01-08 12:28:00 -05:00
dload: extract tempfile creation to its own function
Signed-off-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
c65cea0dcb
commit
f3e2858621
@ -239,6 +239,30 @@ static void unmask_signal(int signal, struct sigaction sa)
|
|||||||
sigaction(signal, &sa, NULL);
|
sigaction(signal, &sa, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static FILE *create_tempfile(struct dload_payload *payload, const char *localpath)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
FILE *fp;
|
||||||
|
char randpath[PATH_MAX];
|
||||||
|
alpm_handle_t *handle = payload->handle;
|
||||||
|
|
||||||
|
/* create a random filename, which is opened with O_EXCL */
|
||||||
|
snprintf(randpath, PATH_MAX, "%salpmtmp.XXXXXX", localpath);
|
||||||
|
if((fd = mkstemp(randpath)) == -1 ||
|
||||||
|
!(fp = fdopen(fd, payload->tempfile_openmode))) {
|
||||||
|
unlink(randpath);
|
||||||
|
close(fd);
|
||||||
|
_alpm_log(handle, ALPM_LOG_ERROR,
|
||||||
|
_("failed to create temporary file for download\n"));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
/* fp now points to our alpmtmp.XXXXXX */
|
||||||
|
STRDUP(payload->tempfile_name, randpath, RET_ERR(handle, ALPM_ERR_MEMORY, NULL));
|
||||||
|
payload->remote_name = strrchr(randpath, '/') + 1;
|
||||||
|
|
||||||
|
return fp;
|
||||||
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
@ -272,27 +296,14 @@ static int curl_download_internal(struct dload_payload *payload,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* URL isn't to a file and ended with a slash */
|
/* URL doesn't contain a filename, so make a tempfile. We can't support
|
||||||
int fd;
|
* resuming this kind of download; partial transfers will be destroyed */
|
||||||
char randpath[PATH_MAX];
|
|
||||||
|
|
||||||
/* we can't support resuming this kind of download, so a partial transfer
|
|
||||||
* will be destroyed */
|
|
||||||
payload->unlink_on_fail = 1;
|
payload->unlink_on_fail = 1;
|
||||||
|
|
||||||
/* create a random filename, which is opened with O_EXCL */
|
localf = create_tempfile(payload, localpath);
|
||||||
snprintf(randpath, PATH_MAX, "%salpmtmp.XXXXXX", localpath);
|
if(localf == NULL) {
|
||||||
if((fd = mkstemp(randpath)) == -1 ||
|
|
||||||
!(localf = fdopen(fd, payload->tempfile_openmode))) {
|
|
||||||
unlink(randpath);
|
|
||||||
close(fd);
|
|
||||||
_alpm_log(handle, ALPM_LOG_ERROR,
|
|
||||||
_("failed to create temporary file for download\n"));
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
/* localf now points to our alpmtmp.XXXXXX */
|
|
||||||
STRDUP(payload->tempfile_name, randpath, RET_ERR(handle, ALPM_ERR_MEMORY, -1));
|
|
||||||
payload->remote_name = strrchr(randpath, '/') + 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_set_handle_opts(payload, error_buffer);
|
curl_set_handle_opts(payload, error_buffer);
|
||||||
|
Loading…
Reference in New Issue
Block a user