]> git.ipfire.org Git - pakfire.git/commitdiff
packages: Fix group parsing for legacy package formats
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 28 Jan 2025 11:16:51 +0000 (11:16 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 28 Jan 2025 11:16:51 +0000 (11:16 +0000)
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 <michael.tremer@ipfire.org>
src/pakfire/archive.c
tests/python/package.py

index 4bc41a6dda60522dea909d42f4ae870ff125443d..0915c8aca5efa73a2c03be06381702fce7c1d423 100644 (file)
@@ -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;
                }
        }
index a7ffc42ede968af92e1cb2fe32d73ba63993a8e8..3f43e3ca3ddd7ca78d3cd928e73f7331c011b28e 100755 (executable)
@@ -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)