]> git.ipfire.org Git - pakfire.git/commitdiff
repo: Add an array for files
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 2 Feb 2025 14:10:30 +0000 (14:10 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 2 Feb 2025 14:10:30 +0000 (14:10 +0000)
This should allow us to add more items whenever we would need to.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/repo.c

index 8309fe4b7b2d6923e4ff6e43b0e5776ba351a18c..a5a0753726843fd6088dfebdb09924f072cc711d 100644 (file)
@@ -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;
 }