return r;
}
+static void pakfire_repo_reset_metadata(struct pakfire_repo* self) {
+ // Reset version and revision
+ self->appdata->repomd.version = 0;
+ self->appdata->repomd.revision = 0;
+}
+
static int pakfire_repo_parse_repomd(struct pakfire_repo* self,
struct pakfire_repomd* repomd, struct json_object* root) {
struct json_object* files = NULL;
// Parse version
r = pakfire_json_get_int64(root, "version", &repomd->version);
if (r < 0)
- return r;
+ goto ERROR;
// Check if we support this version
switch (repomd->version) {
default:
ERROR(self->ctx, "Unsupported version of repository metadata: %ld\n", repomd->version);
- return -ENOTSUP;
+ r = -ENOTSUP;
+ goto ERROR;
}
DEBUG(self->ctx, "Parsing repository metadata in version %ld\n", repomd->version);
// Parse revision
r = pakfire_json_get_int64(root, "revision", &repomd->revision);
if (r < 0)
- return r;
+ goto ERROR;
// Fetch files
r = pakfire_json_get_array(root, "files", &files);
if (r < 0)
- return r;
+ goto ERROR;
// Iterate over all files
for (size_t i = 0; i < json_object_array_length(files); i++) {
// Read type
r = pakfire_json_get_string(file, "type", &type);
if (r < 0)
- return r;
+ goto ERROR;
// Read filename
r = pakfire_json_get_string(file, "filename", &filename);
if (r < 0)
- return r;
+ goto ERROR;
// Read size
r = pakfire_json_get_int64(file, "size", &size);
if (r < 0)
- return r;
+ goto ERROR;
// Fetch checksums
r = pakfire_json_get_object(file, "chksums", &chksums);
if (r < 0)
- return r;
+ goto ERROR;
// Parse checksums
json_object_object_foreach(chksums, hash_name, hexdigest) {
// Import the hexdigest
r = pakfire_hashes_set_hex(&hashes, hash_type, json_object_get_string(hexdigest));
if (r < 0)
- return r;
+ goto ERROR;
}
// We found the packages database
// Store the filename
r = pakfire_string_set(repomd->packages.path, filename);
if (r < 0)
- return r;
+ goto ERROR;
// Store the filelist
repomd->packages.size = size;
// Store the hashes
r = pakfire_hashes_import(&repomd->packages.hashes, &hashes);
if (r < 0)
- return r;
+ goto ERROR;
// Since we currently only know this one file, we can stop once we found it
break;
}
return 0;
+
+ERROR:
+ // If the entire metadata could not be parsed, we reset everything
+ pakfire_repo_reset_metadata(self);
+
+ return r;
}
static int pakfire_repo_read_metadata(struct pakfire_repo* repo, const char* path) {