From: Michael Tremer Date: Tue, 20 Apr 2021 09:32:39 +0000 (+0000) Subject: downloader: Move baseurl into transfer X-Git-Tag: 0.9.28~1285^2~313 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8960e0a24c97697ddf2e6df9937c60785326f5d5;p=pakfire.git downloader: Move baseurl into transfer Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/dist.c b/src/libpakfire/dist.c index 4bb66797d..e0e91a7c7 100644 --- a/src/libpakfire/dist.c +++ b/src/libpakfire/dist.c @@ -38,6 +38,9 @@ #include #include +// XXX for now +#define BASEURL "https://source.ipfire.org/source-3.x/" + #define PAKFIRE_MACROS_DIR "/usr/lib/pakfire/macros" #define PAKFIRE_MACROS_GLOB_PATTERN PAKFIRE_MACROS_DIR "/*.macro" @@ -118,9 +121,6 @@ static int pakfire_dist_create_downloader_and_mirrorlist( return r; } - // Set base URL (XXX) - pakfire_downloader_set_baseurl(*downloader, "https://source.ipfire.org/source-3.x/"); - // Fetch source_dl char** source_dls = pakfire_parser_get_split(makefile, NULL, "source_dl", ' '); @@ -167,7 +167,7 @@ static int pakfire_dist_add_source(Pakfire pakfire, struct pakfire_packager* pac // Download the file if it does not exist in the cache if (access(cache_path, R_OK) != 0) { - r = pakfire_downloader_retrieve(downloader, mirrorlist, filename, cache_path); + r = pakfire_downloader_retrieve(downloader, BASEURL, mirrorlist, filename, cache_path); if (r) return r; } diff --git a/src/libpakfire/downloader.c b/src/libpakfire/downloader.c index df0f4c14b..dc973c9d9 100644 --- a/src/libpakfire/downloader.c +++ b/src/libpakfire/downloader.c @@ -63,6 +63,7 @@ struct pakfire_transfer { FILE* f; // Mirrors + char baseurl[PATH_MAX]; struct pakfire_mirrorlist* mirrors; struct pakfire_mirror* mirror; }; @@ -77,9 +78,6 @@ struct pakfire_downloader { // cURL multi handle CURLM* curl; TAILQ_HEAD(transfers, pakfire_transfer) transfers; - - // Mirror stuff - char baseurl[PATH_MAX]; }; static int pakfire_url_is_absolute(const char* url) { @@ -207,15 +205,6 @@ struct pakfire_downloader* pakfire_downloader_unref(struct pakfire_downloader* d return NULL; } -const char* pakfire_downloader_get_baseurl(struct pakfire_downloader* downloader) { - return downloader->baseurl; -} - -void pakfire_downloader_set_baseurl( - struct pakfire_downloader* downloader, const char* baseurl) { - snprintf(downloader->baseurl, sizeof(downloader->baseurl) - 1, "%s", baseurl); -} - #ifdef ENABLE_DEBUG static int debug_callback(CURL *handle, curl_infotype type, char* data, size_t size, void* private) { @@ -245,13 +234,17 @@ static int debug_callback(CURL *handle, curl_infotype type, #endif static struct pakfire_transfer* pakfire_downloader_create_transfer( - struct pakfire_downloader* downloader, struct pakfire_mirrorlist* mirrors, + struct pakfire_downloader* downloader, const char* baseurl, struct pakfire_mirrorlist* mirrors, const char* url, const char* path) { DEBUG(downloader->pakfire, "Adding download of %s\n", url); + // Reset baseurl it points to an empty string + if (baseurl && !*baseurl) + baseurl = NULL; + // Do not allow relative URLs when no mirrors are set - if (!pakfire_url_is_absolute(url) && !(mirrors || *downloader->baseurl)) { - ERROR(downloader->pakfire, "Relative URLs cannot be used without a mirrorlist\n"); + if (!pakfire_url_is_absolute(url) && !(mirrors || baseurl)) { + ERROR(downloader->pakfire, "Relative URLs cannot be used without a baseurl and/or mirrorlist\n"); errno = EINVAL; return NULL; } @@ -266,6 +259,10 @@ static struct pakfire_transfer* pakfire_downloader_create_transfer( // Copy path pakfire_string_set(transfer->path, path); + // Copy baseurl + if (baseurl) + pakfire_string_set(transfer->baseurl, baseurl); + // Keep a reference to the mirrorlist if (mirrors) transfer->mirrors = pakfire_mirrorlist_ref(mirrors); @@ -303,9 +300,9 @@ ERROR: } int pakfire_downloader_add_transfer(struct pakfire_downloader* downloader, - struct pakfire_mirrorlist* mirrors, const char* url, const char* path) { + const char* baseurl, struct pakfire_mirrorlist* mirrors, const char* url, const char* path) { struct pakfire_transfer* transfer = pakfire_downloader_create_transfer( - downloader, mirrors, url, path); + downloader, baseurl, mirrors, url, path); if (!transfer) return 1; @@ -528,8 +525,8 @@ static int pakfire_downloader_prepare_transfer(struct pakfire_downloader* downlo free(url); // Use baseurl - } else if (*downloader->baseurl) { - char* url = pakfire_url_join(downloader->baseurl, transfer->url); + } else if (*transfer->baseurl) { + char* url = pakfire_url_join(transfer->baseurl, transfer->url); if (!url) { ERROR(downloader->pakfire, "Error composing download URL: %s\n", strerror(errno)); @@ -671,9 +668,9 @@ AGAIN: } int pakfire_downloader_retrieve(struct pakfire_downloader* downloader, - struct pakfire_mirrorlist* mirrors, const char* url, const char* path) { + const char* baseurl, struct pakfire_mirrorlist* mirrors, const char* url, const char* path) { struct pakfire_transfer* transfer = pakfire_downloader_create_transfer( - downloader, mirrors, url, path); + downloader, baseurl, mirrors, url, path); if (!transfer) return 1; diff --git a/src/libpakfire/include/pakfire/downloader.h b/src/libpakfire/include/pakfire/downloader.h index 0f5bfa63e..e193593be 100644 --- a/src/libpakfire/include/pakfire/downloader.h +++ b/src/libpakfire/include/pakfire/downloader.h @@ -33,13 +33,10 @@ int pakfire_downloader_create(struct pakfire_downloader** downloader, Pakfire pa struct pakfire_downloader* pakfire_downloader_ref(struct pakfire_downloader* downloader); struct pakfire_downloader* pakfire_downloader_unref(struct pakfire_downloader* downloader); -const char* pakfire_downloader_get_baseurl(struct pakfire_downloader* downloader); -void pakfire_downloader_set_baseurl(struct pakfire_downloader* downloader, const char* baseurl); - int pakfire_downloader_retrieve(struct pakfire_downloader* downloader, - struct pakfire_mirrorlist* mirrors, const char* url, const char* path); + const char* baseurl, struct pakfire_mirrorlist* mirrors, const char* url, const char* path); int pakfire_downloader_add_transfer(struct pakfire_downloader* downloader, - struct pakfire_mirrorlist* mirrors, const char* url, const char* path); + const char* baseurl, struct pakfire_mirrorlist* mirrors, const char* url, const char* path); int pakfire_downloader_run(struct pakfire_downloader* downloader); diff --git a/src/libpakfire/repo.c b/src/libpakfire/repo.c index 4e4837514..876ff3f54 100644 --- a/src/libpakfire/repo.c +++ b/src/libpakfire/repo.c @@ -151,10 +151,6 @@ static struct pakfire_downloader* pakfire_repo_downloader(PakfireRepo repo) { int r = pakfire_downloader_create(&repo->downloader, repo->pakfire); if (r) return NULL; - - // Set baseurl - if (repo->appdata->baseurl) - pakfire_downloader_set_baseurl(repo->downloader, repo->appdata->baseurl); } return pakfire_downloader_ref(repo->downloader); @@ -203,7 +199,7 @@ static int pakfire_repo_retrieve(PakfireRepo repo, const char* url, const char* mirrorlist = pakfire_repo_get_mirrorlist(repo); // Retrieve the database file - r = pakfire_downloader_retrieve(downloader, mirrorlist, url, path); + r = pakfire_downloader_retrieve(downloader, repo->appdata->baseurl, mirrorlist, url, path); ERROR: if (downloader) @@ -256,7 +252,6 @@ static int pakfire_repo_read_metadata(PakfireRepo repo, const char* path, int re DEBUG(repo->pakfire, "Using package database %s\n", database_filename); } - // Try loading the database if (*database_filename) { pakfire_make_cache_path(repo->pakfire, database_cache_path, diff --git a/src/libpakfire/transaction.c b/src/libpakfire/transaction.c index c127ff52f..686b64bf4 100644 --- a/src/libpakfire/transaction.c +++ b/src/libpakfire/transaction.c @@ -434,10 +434,11 @@ static int pakfire_transaction_download_package(PakfireTransaction transaction, if (!repo) goto ERROR; + // Fetch baseurl + const char* baseurl = pakfire_repo_get_baseurl(repo); + // Fetch mirrorlist mirrorlist = pakfire_repo_get_mirrorlist(repo); - if (!mirrorlist) - goto ERROR; // Where to store the package? cache_path = pakfire_package_get_cache_path(pkg); @@ -450,7 +451,7 @@ static int pakfire_transaction_download_package(PakfireTransaction transaction, goto ERROR; // Add transfer to downloader - r = pakfire_downloader_add_transfer(downloader, mirrorlist, filename, cache_path); + r = pakfire_downloader_add_transfer(downloader, baseurl, mirrorlist, filename, cache_path); ERROR: if (cache_path)