From: Michael Tremer Date: Mon, 5 Sep 2022 15:39:16 +0000 (+0000) Subject: package: Add the filelist to the JSON metadata X-Git-Tag: 0.9.28~324 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ee29252210bdab47eeca09d7ff82df075c3534c7;p=pakfire.git package: Add the filelist to the JSON metadata Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/package.c b/src/libpakfire/package.c index 142ddd07c..055b8ea5c 100644 --- a/src/libpakfire/package.c +++ b/src/libpakfire/package.c @@ -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)