From: Michael Tremer Date: Sat, 12 Oct 2024 19:09:19 +0000 (+0000) Subject: xfer: Only have one way to create a new xfer X-Git-Tag: 0.9.30~1056 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8dd01948f6670d61eaa677c060e1f224bd50ce72;p=pakfire.git xfer: Only have one way to create a new xfer Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/buildservice.c b/src/libpakfire/buildservice.c index e1066cbde..bc36523de 100644 --- a/src/libpakfire/buildservice.c +++ b/src/libpakfire/buildservice.c @@ -62,7 +62,7 @@ static int pakfire_buildservice_xfer_create(struct pakfire_xfer** xfer, va_start(args, url); // Create a new xfer - r = __pakfire_xfer_create(&x, service->ctx, url, args); + r = pakfire_xfer_create(&x, service->ctx, url, args); if (r < 0) goto ERROR; diff --git a/src/libpakfire/daemon.c b/src/libpakfire/daemon.c index 27c166b1b..2061dfb8f 100644 --- a/src/libpakfire/daemon.c +++ b/src/libpakfire/daemon.c @@ -493,12 +493,15 @@ static int pakfire_daemon_close(struct pakfire_xfer* xfer, int code, void* data) } static int pakfire_daemon_xfer_create(struct pakfire_xfer** xfer, - struct pakfire_daemon* daemon, const char* url) { + struct pakfire_daemon* daemon, const char* url, ...) { struct pakfire_xfer* x = NULL; + va_list args; int r; + va_start(args, url); + // Create a new xfer - r = pakfire_xfer_create(&x, daemon->ctx, "%s", url); + r = pakfire_xfer_create(&x, daemon->ctx, url, args); if (r < 0) goto ERROR; @@ -513,6 +516,7 @@ static int pakfire_daemon_xfer_create(struct pakfire_xfer** xfer, ERROR: if (x) pakfire_xfer_unref(x); + va_end(args); return r; } diff --git a/src/libpakfire/dist.c b/src/libpakfire/dist.c index a81c9fa47..4d1407778 100644 --- a/src/libpakfire/dist.c +++ b/src/libpakfire/dist.c @@ -280,16 +280,19 @@ ERROR: } static int pakfire_dist_download_source(struct pakfire_ctx* ctx, - struct pakfire_mirrorlist* mirrorlist, const char* filename, const char* cache_path) { + struct pakfire_mirrorlist* mirrorlist, const char* cache_path, const char* filename, ...) { struct pakfire_xfer* xfer = NULL; + va_list args; int r; // Do not download if the file exists if (pakfire_path_exists(cache_path)) return 0; + va_start(args, filename); + // Create a new transfer - r = pakfire_xfer_create(&xfer, ctx, "%s", filename); + r = pakfire_xfer_create(&xfer, ctx, filename, args); if (r) goto ERROR; @@ -311,6 +314,7 @@ static int pakfire_dist_download_source(struct pakfire_ctx* ctx, ERROR: if (xfer) pakfire_xfer_unref(xfer); + va_end(args); return r; } @@ -330,7 +334,7 @@ static int pakfire_dist_add_source(struct pakfire* pakfire, struct pakfire_packa return r; // Download the source file - r = pakfire_dist_download_source(ctx, mirrorlist, filename, cache_path); + r = pakfire_dist_download_source(ctx, mirrorlist, cache_path, "%s", filename); if (r) return r; diff --git a/src/libpakfire/include/pakfire/xfer.h b/src/libpakfire/include/pakfire/xfer.h index 60cbe8a48..971285b81 100644 --- a/src/libpakfire/include/pakfire/xfer.h +++ b/src/libpakfire/include/pakfire/xfer.h @@ -81,9 +81,7 @@ typedef enum pakfire_transfer_method { PAKFIRE_METHOD_DELETE, } pakfire_xfer_method_t; -int pakfire_xfer_create(struct pakfire_xfer** transfer, struct pakfire_ctx* ctx, - const char* url, ...) __attribute__((format(printf, 3, 4))); -int __pakfire_xfer_create(struct pakfire_xfer** xfer, struct pakfire_ctx* ctx, +int pakfire_xfer_create(struct pakfire_xfer** xfer, struct pakfire_ctx* ctx, const char* url, va_list args) __attribute__((format(printf, 3, 0))); struct pakfire_xfer* pakfire_xfer_ref(struct pakfire_xfer* xfer); diff --git a/src/libpakfire/job.c b/src/libpakfire/job.c index 011183d48..f41635c0a 100644 --- a/src/libpakfire/job.c +++ b/src/libpakfire/job.c @@ -620,7 +620,7 @@ static int pakfire_job_xfer_create(struct pakfire_xfer** xfer, va_start(args, url); // Create a new xfer - r = __pakfire_xfer_create(&x, job->ctx, url, args); + r = pakfire_xfer_create(&x, job->ctx, url, args); if (r < 0) goto ERROR; diff --git a/src/libpakfire/repo.c b/src/libpakfire/repo.c index eda64e423..6f4458d24 100644 --- a/src/libpakfire/repo.c +++ b/src/libpakfire/repo.c @@ -233,13 +233,16 @@ static int __pakfire_repo_path(struct pakfire_repo* repo, settings of this repository. */ static int pakfire_repo_xfer_create( - struct pakfire_xfer** xfer, struct pakfire_repo* repo, const char* url) { + struct pakfire_xfer** xfer, struct pakfire_repo* repo, const char* url, ...) { struct pakfire_mirrorlist* mirrorlist = NULL; const char* baseurl = NULL; + va_list args; int r; + va_start(args, url); + // Create a new transfer - r = pakfire_xfer_create(xfer, repo->ctx, "%s", url); + r = pakfire_xfer_create(xfer, repo->ctx, url, args); if (r < 0) goto ERROR; @@ -268,6 +271,7 @@ ERROR: if (*xfer) pakfire_xfer_unref(*xfer); } + va_end(args); return r; } @@ -435,7 +439,6 @@ static int pakfire_repo_download_database(struct pakfire_repo* repo, const char* filename, const char* path) { struct pakfire_xfer* xfer = NULL; char title[NAME_MAX]; - char url[PATH_MAX]; int r; // Do nothing if the file already exists @@ -451,13 +454,8 @@ static int pakfire_repo_download_database(struct pakfire_repo* repo, if (r) return r; - // Make download URL - r = pakfire_string_format(url, "repodata/%s", filename); - if (r) - return r; - // Create a new transfer - r = pakfire_repo_xfer_create(&xfer, repo, url); + r = pakfire_repo_xfer_create(&xfer, repo, "repodata/%s", filename); if (r) goto ERROR; @@ -616,7 +614,7 @@ static int pakfire_repo_refresh_mirrorlist(struct pakfire_repo* repo, const int } // Create a new xfer - r = pakfire_repo_xfer_create(&xfer, repo, url); + r = pakfire_repo_xfer_create(&xfer, repo, "%s", url); if (r) goto ERROR; @@ -1217,7 +1215,7 @@ int pakfire_repo_download_package(struct pakfire_repo* repo, struct pakfire_http } // Create a new transfer - r = pakfire_repo_xfer_create(&x, repo, url); + r = pakfire_repo_xfer_create(&x, repo, "%s", url); if (r) goto ERROR; @@ -1274,7 +1272,7 @@ static int pakfire_repo_download(struct pakfire_repo* repo, const char* url, } // Create a new transfer - r = pakfire_repo_xfer_create(&xfer, repo, url); + r = pakfire_repo_xfer_create(&xfer, repo, "%s", url); if (r) goto ERROR; diff --git a/src/libpakfire/xfer.c b/src/libpakfire/xfer.c index ff615fe91..7ede9220d 100644 --- a/src/libpakfire/xfer.c +++ b/src/libpakfire/xfer.c @@ -341,18 +341,6 @@ ERROR: } int pakfire_xfer_create(struct pakfire_xfer** xfer, - struct pakfire_ctx* ctx, const char* url, ...) { - va_list args; - int r; - - va_start(args, url); - r = __pakfire_xfer_create(xfer, ctx, url, args); - va_end(args); - - return r; -} - -int __pakfire_xfer_create(struct pakfire_xfer** xfer, struct pakfire_ctx* ctx, const char* url, va_list args) { struct pakfire_xfer* x = NULL; char buffer[PATH_MAX];