int pakfire_json_get_array(struct json_object* json, const char* key, struct json_object** array) {
return __pakfire_json_get_object(json, key, json_type_array, array);
}
+
+int pakfire_json_write(struct json_object* json, const char* path) {
+ FILE* f = NULL;
+ int r;
+
+ // Open the file for writing
+ f = fopen(path, "w");
+ if (!f)
+ return -errno;
+
+ // Write the object to file
+ r = json_object_to_fd(fileno(f), json, 0);
+ if (r < 0) {
+ r = -errno;
+ goto ERROR;
+ }
+
+ERROR:
+ if (f)
+ fclose(f);
+
+ return r;
+}
int pakfire_json_get_object(struct json_object* json, const char* key, struct json_object** object);
int pakfire_json_get_array(struct json_object* json, const char* key, struct json_object** array);
+int pakfire_json_write(struct json_object* json, const char* path);
+
#endif /* PAKFIRE_JSON_H */
if (r < 0)
goto ERROR;
+ // Check if the metadata is more recent than what we had
+ if (repo->appdata->repomd.revision > repomd.revision) {
+ WARN(repo->ctx, "Downloaded metadata is older than what we have. Ignoring.\n");
+
+ // If we have downloaded more recent data, we want to import it
+ } else if (repo->appdata->repomd.revision < repomd.revision) {
+ // Copy the object
+ memcpy(&repo->appdata->repomd, &repomd, sizeof(repo->appdata->repomd));
+
+ // Ensure the parent directory exists
+ r = pakfire_mkparentdir(path, 0755);
+ if (r < 0)
+ goto ERROR;
+
+ // Write the metadata to disk for next time
+ r = pakfire_json_write(json, path);
+ if (r < 0) {
+ ERROR(repo->ctx, "Failed to store repository metadata in %s: %s\n",
+ path, strerror(-r));
+ goto ERROR;
+ }
+ }
+
ERROR:
if (xfer)
pakfire_xfer_unref(xfer);