From 884fcfeb28b58573b98add163b7f62bfaafdb966 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 25 Oct 2022 14:09:04 +0000 Subject: [PATCH] archive: Fetch filelist from JSON for new packages Signed-off-by: Michael Tremer --- src/libpakfire/archive.c | 89 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) diff --git a/src/libpakfire/archive.c b/src/libpakfire/archive.c index 4d8ea0fc5..9841e0f37 100644 --- a/src/libpakfire/archive.c +++ b/src/libpakfire/archive.c @@ -973,8 +973,80 @@ int pakfire_archive_check_digest(struct pakfire_archive* archive, return r; } +static int pakfire_archive_make_filelist_from_json(struct pakfire_archive* archive, + struct pakfire_filelist** filelist) { + struct json_object* array = NULL; + int r; + + struct pakfire_filelist* list = NULL; + struct pakfire_file* file = NULL; + + // Fetch the array with the filelist + array = pakfire_archive_metadata_get_object(archive, "filelist", NULL); + if (!array) { + ERROR(archive->pakfire, "Archive has no filelist: %m\n"); + return 1; + } + + // Determine the length of the array + const size_t length = json_object_array_length(array); + + // End here if the array is empty + if (!length) + return 0; + + // Create a new filelist object + r = pakfire_filelist_create(&list, archive->pakfire); + if (r) + goto ERROR; + + // Walk through all items in this array + for (unsigned int i = 0; i < length; i++) { + struct json_object* item = json_object_array_get_idx(array, i); + if (!item) + continue; + + // Extract the path value + const char* path = json_object_get_string(item); + if (!path) + continue; + + // Create a new file object + r = pakfire_file_create(&file, archive->pakfire); + if (r) + goto ERROR; + + // Set path + r = pakfire_file_set_path(file, path); + if (r) { + pakfire_file_unref(file); + goto ERROR; + } + + // Append the file to the filelist + r = pakfire_filelist_append(list, file); + if (r) { + pakfire_file_unref(file); + goto ERROR; + } + + // Cleanup + pakfire_file_unref(file); + } + + // Reference the filelist + *filelist = pakfire_filelist_ref(list); + +ERROR: + if (list) + pakfire_filelist_unref(list); + + return r; +} + static int pakfire_archive_make_package_from_json(struct pakfire_archive* archive, struct pakfire_repo* repo, struct pakfire_package** package) { + struct pakfire_filelist* filelist = NULL; int r; // Calculate digest @@ -1143,11 +1215,26 @@ static int pakfire_archive_make_package_from_json(struct pakfire_archive* archiv } } + // Fetch the filelist + r = pakfire_archive_make_filelist_from_json(archive, &filelist); + if (r) + goto ERROR; + + // Store the filelist + if (filelist) { + r = pakfire_package_set_filelist(pkg, filelist); + if (r) + goto ERROR; + } + // Success! *package = pkg; - return 0; + r = 0; ERROR: + if (filelist) + pakfire_filelist_unref(filelist); + return r; } -- 2.39.5