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];
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;
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;
}