]> git.ipfire.org Git - pakfire.git/commitdiff
package: Add the filelist to the JSON metadata
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 5 Sep 2022 15:39:16 +0000 (15:39 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 5 Sep 2022 15:39:16 +0000 (15:39 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/package.c

index 142ddd07c25ce02d02714827832c352f80404985..055b8ea5c6105449e52f116f5688ecc2d4e44b1d 100644 (file)
@@ -1519,6 +1519,76 @@ ERROR:
        return r;
 }
 
+static int __pakfire_package_add_json_filelist(struct pakfire* pakfire,
+               struct pakfire_file* file, void* data) {
+       struct json_object* filelist = (struct json_object*)data;
+       int r = 1;
+
+       // Fetch the file path
+       const char* path = pakfire_file_get_path(file);
+
+       // Create a new JSON string
+       struct json_object* object = json_object_new_string(path);
+       if (!object)
+               goto ERROR;
+
+       // Append the string
+       r = json_object_array_add(filelist, object);
+       if (r)
+               goto ERROR;
+
+       return 0;
+
+ERROR:
+       // Free JSON string
+       if (object)
+               json_object_put(object);
+
+       return r;
+}
+
+static int pakfire_package_add_json_filelist(
+               struct pakfire_package* pkg, struct json_object* md) {
+       struct pakfire_filelist* filelist = NULL;
+       struct json_object* object = NULL;
+       int r;
+
+       // Fetch the filelist
+       filelist = pakfire_package_get_filelist(pkg);
+       if (!filelist) {
+               ERROR(pkg->pakfire, "Could not fetch package filelist\n");
+               r = 1;
+               goto ERROR;
+       }
+
+       // Create a new JSON array
+       object = json_object_new_array();
+       if (!object) {
+               ERROR(pkg->pakfire, "Could not create a JSON array\n");
+               r = 1;
+               goto ERROR;
+       }
+
+       // Walk through the filelist
+       r = pakfire_filelist_walk(filelist, __pakfire_package_add_json_filelist, object);
+       if (r)
+               goto ERROR;
+
+       // Add object
+       r = json_object_object_add(md, "filelist", object);
+       if (r)
+               goto ERROR;
+
+ERROR:
+       // Free JSON object on error
+       if (r)
+               json_object_put(object);
+       if (filelist)
+               pakfire_filelist_unref(filelist);
+
+       return r;
+}
+
 static int pakfire_package_add_build_metadata(struct pakfire_package* pkg,
                struct json_object* md) {
        int r;
@@ -1705,6 +1775,11 @@ struct json_object* pakfire_package_to_json(struct pakfire_package* pkg) {
        if (r)
                goto ERROR;
 
+       // Generate filelist
+       r = pakfire_package_add_json_filelist(pkg, md);
+       if (r)
+               goto ERROR;
+
        // Generate build metadata
        r = pakfire_package_add_build_metadata(pkg, md);
        if (r)