From: Michael Tremer Date: Tue, 20 Apr 2021 09:57:57 +0000 (+0000) Subject: downloader: Add title to transfers X-Git-Tag: 0.9.28~1285^2~308 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e60f98d54ca038236eab8a764f12388d55e437b4;p=pakfire.git downloader: Add title to transfers This allows us to set a custom title and not show any cryptic filenames Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/dist.c b/src/libpakfire/dist.c index e0e91a7c7..9bcdc6ea2 100644 --- a/src/libpakfire/dist.c +++ b/src/libpakfire/dist.c @@ -167,7 +167,8 @@ 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, BASEURL, mirrorlist, filename, cache_path); + r = pakfire_downloader_retrieve(downloader, BASEURL, mirrorlist, + NULL, filename, cache_path); if (r) return r; } diff --git a/src/libpakfire/downloader.c b/src/libpakfire/downloader.c index dc973c9d9..f33cbfbe3 100644 --- a/src/libpakfire/downloader.c +++ b/src/libpakfire/downloader.c @@ -54,6 +54,7 @@ struct pakfire_transfer { TAILQ_ENTRY(pakfire_transfer) nodes; CURL* handle; + char title[NAME_MAX]; char url[PATH_MAX]; char path[PATH_MAX]; int tries; @@ -235,7 +236,7 @@ static int debug_callback(CURL *handle, curl_infotype type, static struct pakfire_transfer* pakfire_downloader_create_transfer( struct pakfire_downloader* downloader, const char* baseurl, struct pakfire_mirrorlist* mirrors, - const char* url, const char* path) { + const char* title, const char* url, const char* path) { DEBUG(downloader->pakfire, "Adding download of %s\n", url); // Reset baseurl it points to an empty string @@ -253,6 +254,19 @@ static struct pakfire_transfer* pakfire_downloader_create_transfer( if (!transfer) return NULL; + // Copy title + if (title) { + pakfire_string_set(transfer->title, title); + + // Or use the filename + } else { + char* filename = pakfire_basename(url); + if (filename) { + pakfire_string_set(transfer->title, filename); + free(filename); + } + } + // Copy URL pakfire_string_set(transfer->url, url); @@ -300,9 +314,10 @@ ERROR: } int pakfire_downloader_add_transfer(struct pakfire_downloader* downloader, - const char* baseurl, struct pakfire_mirrorlist* mirrors, const char* url, const char* path) { + const char* baseurl, struct pakfire_mirrorlist* mirrors, const char* title, + const char* url, const char* path) { struct pakfire_transfer* transfer = pakfire_downloader_create_transfer( - downloader, baseurl, mirrors, url, path); + downloader, baseurl, mirrors, title, url, path); if (!transfer) return 1; @@ -581,10 +596,8 @@ static int pakfire_downloader_make_single_progressbar( pakfire_progressbar_reset(downloader->progressbar); // Add title - char* filename = pakfire_basename(transfer->url); - if (filename) { - r = pakfire_progressbar_add_string(downloader->progressbar, "%s", filename); - free(filename); + if (transfer->title) { + r = pakfire_progressbar_add_string(downloader->progressbar, "%s", transfer->title); if (r) return r; } @@ -668,9 +681,10 @@ AGAIN: } int pakfire_downloader_retrieve(struct pakfire_downloader* downloader, - const char* baseurl, struct pakfire_mirrorlist* mirrors, const char* url, const char* path) { + const char* baseurl, struct pakfire_mirrorlist* mirrors, const char* title, + const char* url, const char* path) { struct pakfire_transfer* transfer = pakfire_downloader_create_transfer( - downloader, baseurl, mirrors, url, path); + downloader, baseurl, mirrors, title, url, path); if (!transfer) return 1; diff --git a/src/libpakfire/include/pakfire/downloader.h b/src/libpakfire/include/pakfire/downloader.h index e193593be..b24c5eb8b 100644 --- a/src/libpakfire/include/pakfire/downloader.h +++ b/src/libpakfire/include/pakfire/downloader.h @@ -34,9 +34,11 @@ struct pakfire_downloader* pakfire_downloader_ref(struct pakfire_downloader* dow struct pakfire_downloader* pakfire_downloader_unref(struct pakfire_downloader* downloader); int pakfire_downloader_retrieve(struct pakfire_downloader* downloader, - const char* baseurl, struct pakfire_mirrorlist* mirrors, const char* url, const char* path); + const char* baseurl, struct pakfire_mirrorlist* mirrors, const char* title, + const char* url, const char* path); int pakfire_downloader_add_transfer(struct pakfire_downloader* downloader, - const char* baseurl, struct pakfire_mirrorlist* mirrors, const char* url, const char* path); + const char* baseurl, struct pakfire_mirrorlist* mirrors, const char* title, + 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 4b17c3b9c..1bba7117e 100644 --- a/src/libpakfire/repo.c +++ b/src/libpakfire/repo.c @@ -174,7 +174,8 @@ struct pakfire_mirrorlist* pakfire_repo_get_mirrorlist(PakfireRepo repo) { return pakfire_mirrorlist_ref(repo->mirrorlist); } -static int pakfire_repo_retrieve(PakfireRepo repo, const char* url, const char* path) { +static int pakfire_repo_retrieve(PakfireRepo repo, const char* title, + const char* url, const char* path) { struct pakfire_mirrorlist* mirrorlist = NULL; struct pakfire_downloader* downloader; @@ -186,7 +187,8 @@ 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, repo->appdata->baseurl, mirrorlist, url, path); + r = pakfire_downloader_retrieve(downloader, repo->appdata->baseurl, mirrorlist, + title, url, path); if (mirrorlist) pakfire_mirrorlist_unref(mirrorlist); @@ -197,6 +199,7 @@ static int pakfire_repo_retrieve(PakfireRepo repo, const char* url, const char* static int pakfire_repo_download_database(PakfireRepo repo, const char* database, const char* cache_path) { + char title[NAME_MAX]; char database_url[PATH_MAX]; // Do nothing if the file already exists @@ -205,10 +208,15 @@ static int pakfire_repo_download_database(PakfireRepo repo, const char* database return 0; } + const char* name = pakfire_repo_get_name(repo); + + // Make title + pakfire_string_format(title, _("Package Database: %s"), name); + // Make download URL pakfire_string_format(database_url, "repodata/%s", database); - return pakfire_repo_retrieve(repo, database_url, cache_path); + return pakfire_repo_retrieve(repo, title, database_url, cache_path); } static int pakfire_repo_read_metadata(PakfireRepo repo, const char* path, int refresh) { @@ -292,7 +300,7 @@ static int pakfire_repo_refresh_mirrorlist(PakfireRepo repo, const int force) { } } - return pakfire_repo_retrieve(repo, + return pakfire_repo_retrieve(repo, NULL, repo->appdata->mirrorlist_url, repo->appdata->mirrorlist); } @@ -307,7 +315,7 @@ static int pakfire_repo_refresh_metadata(PakfireRepo repo, const int force) { } } - int r = pakfire_repo_retrieve(repo, "repodata/repomd.json", repo->appdata->metadata); + int r = pakfire_repo_retrieve(repo, NULL, "repodata/repomd.json", repo->appdata->metadata); if (r) return r; diff --git a/src/libpakfire/transaction.c b/src/libpakfire/transaction.c index 686b64bf4..b690ba35d 100644 --- a/src/libpakfire/transaction.c +++ b/src/libpakfire/transaction.c @@ -428,6 +428,7 @@ static int pakfire_transaction_download_package(PakfireTransaction transaction, PakfireRepo repo = NULL; struct pakfire_mirrorlist* mirrorlist = NULL; char* cache_path = NULL; + char* nevra = NULL; // Fetch the repository to download from repo = pakfire_package_get_repo(pkg); @@ -450,10 +451,17 @@ static int pakfire_transaction_download_package(PakfireTransaction transaction, if (!filename) goto ERROR; + nevra = pakfire_package_get_nevra(pkg); + if (!nevra) + goto ERROR; + // Add transfer to downloader - r = pakfire_downloader_add_transfer(downloader, baseurl, mirrorlist, filename, cache_path); + r = pakfire_downloader_add_transfer(downloader, baseurl, mirrorlist, + nevra, filename, cache_path); ERROR: + if (nevra) + free(nevra); if (cache_path) free(cache_path); if (mirrorlist)