]> git.ipfire.org Git - pakfire.git/commitdiff
packages: Accept format arguments when adding a new dependency
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 3 Jan 2025 07:53:53 +0000 (07:53 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 3 Jan 2025 07:53:53 +0000 (07:53 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/archive.c
src/pakfire/build.c
src/pakfire/deps.c
src/pakfire/package.c
src/pakfire/package.h

index 33a0fbc2b788992cecfcc78c56f5b05057f51c31..cebd995dd8b38a7961dcfd2e6ea55a137e6abbaf 100644 (file)
@@ -1721,7 +1721,7 @@ static int pakfire_archive_make_package_from_json(struct pakfire_archive* archiv
                                continue;
 
                        // Add the dependency to the package
-                       r = pakfire_package_add_dep(pkg, dep->key, string);
+                       r = pakfire_package_add_dep(pkg, dep->key, "%s", string);
                        if (r)
                                goto ERROR;
                }
index 76cc08fcd53ae6d6b1baa8ba1c4dcad72965564f..42026887e4a11a363b51e9ef7f03bd25f780e299 100644 (file)
@@ -472,7 +472,7 @@ static int pakfire_build_process_deps(struct pakfire_ctx* ctx, void* data,
        }
 
        // Add dependency
-       r = pakfire_package_add_dep(p->pkg, p->dep, dep);
+       r = pakfire_package_add_dep(p->pkg, p->dep, "%s", dep);
        if (r < 0) {
                ERROR(ctx, "Could not process dependency '%s': %s\n", dep, strerror(-r));
                goto ERROR;
index a682333f89bf016e44d398ca2ed9a6c5777392c9..b001eb73e534933366ada034e1c5984765658b83 100644 (file)
@@ -371,7 +371,7 @@ int pakfire_str2deps(struct pakfire* pakfire, struct pakfire_package* pkg,
        // Walk through the buffer line by line
        while (dep) {
                // Add the dependency
-               r = pakfire_package_add_dep(pkg, key, dep);
+               r = pakfire_package_add_dep(pkg, key, "%s", dep);
                if (r)
                        goto ERROR;
 
index 4d5916a9224d96523b78a974b6b37f8256ee8a9b..b0958a558969f750ebec75e017fa7c410d56220c 100644 (file)
@@ -1370,16 +1370,27 @@ SUCCESS:
 }
 
 int pakfire_package_add_dep(struct pakfire_package* pkg,
-               const enum pakfire_package_key key, const char* dep) {
+               const enum pakfire_package_key key, const char* format, ...) {
+       char buffer[PATH_MAX];
+       va_list args;
+       int r;
+
+       // Format the dependency
+       va_start(args, format);
+       r = pakfire_string_vformat(buffer, format, args);
+       va_end(args);
+       if (r < 0)
+               return r;
+
        // Ignore comments
-       if (pakfire_string_startswith(dep, "#"))
+       if (pakfire_string_startswith(buffer, "#"))
                return 0;
 
        // Parse the dependency
-       Id id = pakfire_str2dep(pkg->pakfire, dep);
+       Id id = pakfire_str2dep(pkg->pakfire, buffer);
        if (!id) {
                ERROR(pkg->ctx, "Could not add dependency '%s' to %s\n",
-                       dep, pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA));
+                       buffer, pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA));
 
                return -EINVAL;
        }
index 3558d7dcebb6751f6a76cbd80e48a649762edbce..d1f8519c3fe302e6374b72f7219c9250082b0fb8 100644 (file)
@@ -174,7 +174,8 @@ int pakfire_package_append_file(struct pakfire_package* pkg, const char* path);
 
 // Dependencies
 int pakfire_package_add_dep(struct pakfire_package* pkg,
-       const enum pakfire_package_key key, const char* dep);
+       const enum pakfire_package_key key, const char* format, ...)
+       __attribute__((format(printf, 3, 4)));
 
 int pakfire_package_has_rich_deps(struct pakfire_package* pkg);
 int pakfire_package_matches_dep(struct pakfire_package* pkg,