[libosinfo PATCH] loader: Fully support multiple short-id values

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



osinfo-db schema allows for multiple short-id, and there's already some
entries that rely on that. For example, debian and ubuntu have something
like:
```
<short-id>debian9</short-id>
<short-id>debianstretch</short-id>
```

or

```
<short-id>ubuntu19.04</short-id>
<short-id>ubuntudisco</short-id>
```

However, OsinfoLoader has always been treating "short-id" as a single
property entry and, as a consequence of this, apps would always have to
use the first listed id as shown below:
```
fidencio@dahmer ~/src/upstream/libosinfo $ osinfo-install-script debian9
preseed.cfg
fidencio@dahmer ~/src/upstream/libosinfo $ osinfo-install-script debianstretch
Error finding OS: debianstretch
fidencio@dahmer ~/src/upstream/libosinfo $ osinfo-install-script ubuntu19.04
preseed.cfg
fidencio@dahmer ~/src/upstream/libosinfo $ osinfo-install-script ubuntudisco
Error finding OS: ubuntudisco
```

As OsinfoEntity already has support for multiple property entries, let's
take advantage of this and properly treat OSINFO_PRODUCT_PROP_SHORT_ID as
so.

This doesn't break any compatibility with the existent code as
osinfo_entity_get_param_value() will *always* return the first added
entry, as it was done before.

OsinfoFilter also already has support for multiple property entries and
the filter works as expected.

Here's the result of the very same example used above with this fix:
```
fidencio@dahmer ~/src/upstream/libosinfo $ ./tools/osinfo-install-script debian9
preseed.cfg
fidencio@dahmer ~/src/upstream/libosinfo $ ./tools/osinfo-install-script debianstretch
preseed.cfg
fidencio@dahmer ~/src/upstream/libosinfo $ ./tools/osinfo-install-script ubuntu19.04
preseed.cfg
fidencio@dahmer ~/src/upstream/libosinfo $ ./tools/osinfo-install-script ubuntudisco
preseed.cfg
````

https://gitlab.com/libosinfo/libosinfo/issues/19

Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
 osinfo/osinfo_loader.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
index 05e9d98..522162f 100644
--- a/osinfo/osinfo_loader.c
+++ b/osinfo/osinfo_loader.c
@@ -709,17 +709,28 @@ static void osinfo_loader_product(OsinfoLoader *loader,
         { OSINFO_PRODUCT_PROP_VENDOR, G_TYPE_STRING },
         { OSINFO_PRODUCT_PROP_VERSION, G_TYPE_STRING },
         { OSINFO_PRODUCT_PROP_LOGO, G_TYPE_STRING },
-        { OSINFO_PRODUCT_PROP_SHORT_ID, G_TYPE_STRING },
         { OSINFO_PRODUCT_PROP_RELEASE_DATE, G_TYPE_STRING },
         { OSINFO_PRODUCT_PROP_EOL_DATE, G_TYPE_STRING },
         { OSINFO_PRODUCT_PROP_CODENAME, G_TYPE_STRING },
         { NULL, G_TYPE_INVALID }
     };
+    xmlNodePtr *nodes = NULL;
+    gsize nnodes, i;
 
     osinfo_loader_entity(loader, OSINFO_ENTITY(product), keys, ctxt, root, err);
     if (error_is_set(err))
         return;
 
+    nnodes = osinfo_loader_nodeset("./short-id", loader, ctxt, &nodes, err);
+    if (error_is_set(err))
+        return;
+
+    for (i = 0; i < nnodes; i++)
+        osinfo_entity_add_param(OSINFO_ENTITY(product),
+                                OSINFO_PRODUCT_PROP_SHORT_ID,
+                                (const gchar *)nodes[i]->children->content);
+    g_free(nodes);
+
     osinfo_loader_product_relshp(loader, product,
                                  OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM,
                                  "derives-from",
-- 
2.21.0

_______________________________________________
Libosinfo mailing list
Libosinfo@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libosinfo




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Fedora Users]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux