From: Michael Tremer Date: Tue, 28 Jan 2025 11:16:51 +0000 (+0000) Subject: packages: Fix group parsing for legacy package formats X-Git-Tag: 0.9.30~325 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d256ad614a6c1eda202f3c6158e6234eee5b840d;p=pakfire.git packages: Fix group parsing for legacy package formats In older package formats, we stored the groups as a string. The current test package is in this format and the added code ensures that we can parse the group. Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/archive.c b/src/pakfire/archive.c index 4bc41a6d..0915c8ac 100644 --- a/src/pakfire/archive.c +++ b/src/pakfire/archive.c @@ -1607,20 +1607,30 @@ static int pakfire_archive_make_package_from_json(struct pakfire_archive* archiv // Groups struct json_object* groups = pakfire_archive_metadata_get_object(archive, "groups", NULL); - if (groups && json_object_is_type(groups, json_type_array)) { - const size_t length = json_object_array_length(groups); - for (unsigned int i = 0; i < length; i++) { - struct json_object* item = json_object_array_get_idx(groups, i); - if (!item) - continue; + if (groups) { + if (json_object_is_type(groups, json_type_array)) { + const size_t length = json_object_array_length(groups); - const char* group = json_object_get_string(item); - if (!group) - continue; + for (unsigned int i = 0; i < length; i++) { + struct json_object* item = json_object_array_get_idx(groups, i); + if (!item) + continue; - r = pakfire_package_add_string(pkg, PAKFIRE_PKG_GROUPS, group); - if (r) + const char* group = json_object_get_string(item); + if (!group) + continue; + + r = pakfire_package_add_string(pkg, PAKFIRE_PKG_GROUPS, group); + if (r) + goto ERROR; + } + + // Compatibility code for when groups where stored as a simple string + } else if (json_object_is_type(groups, json_type_string)) { + r = pakfire_package_add_string(pkg, + PAKFIRE_PKG_GROUPS, json_object_get_string(groups)); + if (r < 0) goto ERROR; } } diff --git a/tests/python/package.py b/tests/python/package.py index a7ffc42e..3f43e3ca 100755 --- a/tests/python/package.py +++ b/tests/python/package.py @@ -36,7 +36,7 @@ class PackageTest(tests.TestCase): self.assertEqual(p.license, "GPLv2+") self.assertEqual(p.vendor, "IPFire Project") self.assertEqual(p.distribution, "ipfire3") - self.assertEqual(p.groups, "Applications/System") + self.assertEqual(p.groups, ["Applications/System"]) self.assertEqual(p.uuid, "a20dddff-d8e8-4544-aaee-8bab618b0b3f") self.assertIsNone(p.packager)