From 6fadf448fc610c11c92fa406e4bc2292dcbff6b4 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sun, 2 Feb 2025 14:10:30 +0000 Subject: [PATCH] repo: Add an array for files This should allow us to add more items whenever we would need to. Signed-off-by: Michael Tremer --- src/pakfire/repo.c | 51 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/src/pakfire/repo.c b/src/pakfire/repo.c index 8309fe4b..a5a07537 100644 --- a/src/pakfire/repo.c +++ b/src/pakfire/repo.c @@ -1965,6 +1965,48 @@ int pakfire_repo_refresh(struct pakfire_repo* repo, int force) { return 0; } +static int pakfire_repo_metadata_add_file( + struct pakfire_repo* self, struct json_object* repomd, const char* filename) { + struct json_object* files = NULL; + struct json_object* file = NULL; + int r; + + // Fetch the files array + files = json_object_object_get(repomd, "files"); + if (!files) { + ERROR(self->ctx, "Repository metadata does not seem to have a files array\n"); + return -ENOENT; + } + + // Create a new object + file = pakfire_json_new_object(); + if (!file) { + ERROR(self->ctx, "Failed to create a new file object: %m\n"); + r = -errno; + goto ERROR; + } + + // Add the filename + r = pakfire_json_add_string(file, "filename", filename); + if (r < 0) + goto ERROR; + + // Append it to the files array + r = json_object_array_add(files, file); + if (r < 0) { + ERROR(self->ctx, "Failed to add the file to the files array\n"); + goto ERROR; + } + + return 0; + +ERROR: + if (file) + json_object_put(file); + + return r; +} + static int pakfire_repo_write_database(struct pakfire_repo* self, struct json_object* repomd, char* filename, size_t length) { char database[PATH_MAX]; @@ -2023,8 +2065,8 @@ static int pakfire_repo_write_database(struct pakfire_repo* self, goto ERROR; } - // Add the database name to the repository metadata - r = pakfire_json_add_string(repomd, "database", filename); + // Add the database to the filelist + r = pakfire_repo_metadata_add_file(self, repomd, filename); if (r < 0) goto ERROR; @@ -2053,6 +2095,11 @@ static int pakfire_repo_make_metadata(struct pakfire_repo* self, struct json_obj if (r < 0) return r; + // Add a new files array + r = pakfire_json_add_array(md, "files", NULL); + if (r < 0) + return r; + return 0; } -- 2.39.5