]> git.ipfire.org Git - pakfire.git/commitdiff
downloader: Add title to transfers
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 20 Apr 2021 09:57:57 +0000 (09:57 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 20 Apr 2021 09:57:57 +0000 (09:57 +0000)
This allows us to set a custom title and not show any cryptic filenames

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/dist.c
src/libpakfire/downloader.c
src/libpakfire/include/pakfire/downloader.h
src/libpakfire/repo.c
src/libpakfire/transaction.c

index e0e91a7c7fe6b4eaeaef178a4fd620f68f62e8c7..9bcdc6ea2bdd5fccc646495b054ccfb2c2b37a9c 100644 (file)
@@ -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;
        }
index dc973c9d9474cd8b0b5ec5005b5dab5b44a80b4f..f33cbfbe31181dbf931a3e83b07f6b148da78f15 100644 (file)
@@ -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;
 
index e193593be4ac9dff193db1d69ab108b161bd5a88..b24c5eb8bad56d1ef8846ba529d045b45d17ef91 100644 (file)
@@ -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);
 
index 4b17c3b9c0e43a7cf24cbe55578b02ffe210b191..1bba7117eb842f8876bb06befc7c3d1599ea49cd 100644 (file)
@@ -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;
 
index 686b64bf40b6c285ec60c61bd40f2f96fad02648..b690ba35dd6056adcc191129ecdbe98291eb5b77 100644 (file)
@@ -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)