mirror of
https://github.com/moparisthebest/pacman
synced 2024-12-21 23:38:49 -05:00
dload: pass back the effective URL to callers of _alpm_download
I suspect that eventually we're going to end up returning a pointer to an allocated struct to describe the download result, but that's for another patch when the need arises... Fixes FS#33508. Signed-off-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
f21e1f54aa
commit
27067b1372
@ -218,7 +218,7 @@ int SYMEXPORT alpm_db_update(int force, alpm_db_t *db)
|
||||
payload.force = force;
|
||||
payload.unlink_on_fail = 1;
|
||||
|
||||
ret = _alpm_download(&payload, syncpath, NULL);
|
||||
ret = _alpm_download(&payload, syncpath, NULL, NULL);
|
||||
_alpm_dload_payload_reset(&payload);
|
||||
|
||||
if(ret == 0 && (level & ALPM_SIG_DATABASE)) {
|
||||
@ -244,7 +244,7 @@ int SYMEXPORT alpm_db_update(int force, alpm_db_t *db)
|
||||
/* set hard upper limit of 16KiB */
|
||||
payload.max_size = 16 * 1024;
|
||||
|
||||
sig_ret = _alpm_download(&payload, syncpath, NULL);
|
||||
sig_ret = _alpm_download(&payload, syncpath, NULL, NULL);
|
||||
/* errors_ok suppresses error messages, but not the return code */
|
||||
sig_ret = payload.errors_ok ? 0 : sig_ret;
|
||||
_alpm_dload_payload_reset(&payload);
|
||||
|
@ -386,7 +386,7 @@ static FILE *create_tempfile(struct dload_payload *payload, const char *localpat
|
||||
#define HOSTNAME_SIZE 256
|
||||
|
||||
static int curl_download_internal(struct dload_payload *payload,
|
||||
const char *localpath, char **final_file)
|
||||
const char *localpath, char **final_file, char **final_url)
|
||||
{
|
||||
int ret = -1;
|
||||
FILE *localf = NULL;
|
||||
@ -523,6 +523,10 @@ static int curl_download_internal(struct dload_payload *payload,
|
||||
curl_easy_getinfo(curl, CURLINFO_CONDITION_UNMET, &timecond);
|
||||
curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &effective_url);
|
||||
|
||||
if(final_url != NULL) {
|
||||
*final_url = effective_url;
|
||||
}
|
||||
|
||||
/* time condition was met and we didn't download anything. we need to
|
||||
* clean up the 0 byte .part file that's left behind. */
|
||||
if(timecond == 1 && DOUBLE_EQ(bytes_dl, 0)) {
|
||||
@ -613,13 +617,13 @@ cleanup:
|
||||
* @return 0 on success, -1 on error (pm_errno is set accordingly if errors_ok == 0)
|
||||
*/
|
||||
int _alpm_download(struct dload_payload *payload, const char *localpath,
|
||||
char **final_file)
|
||||
char **final_file, char **final_url)
|
||||
{
|
||||
alpm_handle_t *handle = payload->handle;
|
||||
|
||||
if(handle->fetchcb == NULL) {
|
||||
#ifdef HAVE_LIBCURL
|
||||
return curl_download_internal(payload, localpath, final_file);
|
||||
return curl_download_internal(payload, localpath, final_file, final_url);
|
||||
#else
|
||||
RET_ERR(handle, ALPM_ERR_EXTERNAL_DOWNLOAD, -1);
|
||||
#endif
|
||||
@ -653,7 +657,7 @@ char SYMEXPORT *alpm_fetch_pkgurl(alpm_handle_t *handle, const char *url)
|
||||
{
|
||||
char *filepath;
|
||||
const char *cachedir;
|
||||
char *final_file = NULL;
|
||||
char *final_file = NULL, *final_pkg_url = NULL;
|
||||
struct dload_payload payload;
|
||||
int ret = 0;
|
||||
|
||||
@ -673,7 +677,7 @@ char SYMEXPORT *alpm_fetch_pkgurl(alpm_handle_t *handle, const char *url)
|
||||
payload.handle = handle;
|
||||
|
||||
/* download the file */
|
||||
ret = _alpm_download(&payload, cachedir, &final_file);
|
||||
ret = _alpm_download(&payload, cachedir, &final_file, &final_pkg_url);
|
||||
_alpm_dload_payload_reset(&payload);
|
||||
if(ret == -1) {
|
||||
_alpm_log(handle, ALPM_LOG_WARNING, _("failed to download %s\n"), url);
|
||||
@ -688,9 +692,9 @@ char SYMEXPORT *alpm_fetch_pkgurl(alpm_handle_t *handle, const char *url)
|
||||
char *sig_filepath, *sig_final_file = NULL;
|
||||
size_t len;
|
||||
|
||||
len = strlen(url) + 5;
|
||||
len = strlen(final_pkg_url) + 5;
|
||||
MALLOC(payload.fileurl, len, RET_ERR(handle, ALPM_ERR_MEMORY, NULL));
|
||||
snprintf(payload.fileurl, len, "%s.sig", url);
|
||||
snprintf(payload.fileurl, len, "%s.sig", final_pkg_url);
|
||||
|
||||
sig_filepath = filecache_find_url(handle, payload.fileurl);
|
||||
if(sig_filepath == NULL) {
|
||||
@ -701,7 +705,7 @@ char SYMEXPORT *alpm_fetch_pkgurl(alpm_handle_t *handle, const char *url)
|
||||
/* set hard upper limit of 16KiB */
|
||||
payload.max_size = 16 * 1024;
|
||||
|
||||
ret = _alpm_download(&payload, cachedir, &sig_final_file);
|
||||
ret = _alpm_download(&payload, cachedir, &sig_final_file, NULL);
|
||||
if(ret == -1 && !payload.errors_ok) {
|
||||
_alpm_log(handle, ALPM_LOG_WARNING,
|
||||
_("failed to download %s\n"), payload.fileurl);
|
||||
|
@ -48,7 +48,7 @@ struct dload_payload {
|
||||
void _alpm_dload_payload_reset(struct dload_payload *payload);
|
||||
|
||||
int _alpm_download(struct dload_payload *payload, const char *localpath,
|
||||
char **final_file);
|
||||
char **final_file, char **final_url);
|
||||
|
||||
#endif /* _ALPM_DLOAD_H */
|
||||
|
||||
|
@ -877,7 +877,7 @@ static int download_single_file(alpm_handle_t *handle, struct dload_payload *pay
|
||||
MALLOC(payload->fileurl, len, RET_ERR(handle, ALPM_ERR_MEMORY, -1));
|
||||
snprintf(payload->fileurl, len, "%s/%s", server_url, payload->remote_name);
|
||||
|
||||
if(_alpm_download(payload, cachedir, NULL) != -1) {
|
||||
if(_alpm_download(payload, cachedir, NULL, NULL) != -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user