[Libosinfo] [libosinfo PATCH 1/3] tree: Add osinfo_tree_has_treeinfo()

Fabiano Fidêncio fidencio at redhat.com
Mon Dec 10 12:37:35 UTC 2018


As not all the "trees" we stored in osinfo-db have "treeinfo" data,
let's add a new method, osinfo_tree_has_treeinfo(), that can be used to
check whether the tree has treeinfo or not.

Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
 osinfo/libosinfo.syms  |  2 ++
 osinfo/osinfo_loader.c | 25 +++++++++++++++++--------
 osinfo/osinfo_tree.c   | 39 +++++++++++++++++++++++++++++++++++++++
 osinfo/osinfo_tree.h   |  3 +++
 4 files changed, 61 insertions(+), 8 deletions(-)

diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index 39906c4..d87b7c0 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -548,6 +548,8 @@ LIBOSINFO_1.3.0 {
 	osinfo_os_get_all_device_links;
 	osinfo_os_get_image_list;
 	osinfo_os_get_maximum_resources;
+
+	osinfo_tree_has_treeinfo;
 } LIBOSINFO_0.2.13;
 
 /* Symbols in next release...
diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
index 17cb563..cea5070 100644
--- a/osinfo/osinfo_loader.c
+++ b/osinfo/osinfo_loader.c
@@ -1195,7 +1195,7 @@ static OsinfoTree *osinfo_loader_tree(OsinfoLoader *loader,
 {
     xmlNodePtr *nodes = NULL;
     guint i;
-
+    gboolean has_treeinfo = FALSE;
     gchar *arch = (gchar *)xmlGetProp(root, BAD_CAST "arch");
     const OsinfoEntityKey keys[] = {
         { OSINFO_TREE_PROP_URL, G_TYPE_STRING },
@@ -1222,27 +1222,36 @@ static OsinfoTree *osinfo_loader_tree(OsinfoLoader *loader,
             continue;
 
         if (g_str_equal((const gchar *)nodes[i]->name,
-                        OSINFO_TREE_PROP_TREEINFO_FAMILY + strlen("treeinfo-")))
+                        OSINFO_TREE_PROP_TREEINFO_FAMILY + strlen("treeinfo-"))) {
             osinfo_entity_set_param(OSINFO_ENTITY(tree),
                                     OSINFO_TREE_PROP_TREEINFO_FAMILY,
                                     (const gchar *)nodes[i]->children->content);
-        else if (g_str_equal((const gchar *)nodes[i]->name,
-                             OSINFO_TREE_PROP_TREEINFO_VARIANT + strlen("treeinfo-")))
+            has_treeinfo = TRUE;
+        } else if (g_str_equal((const gchar *)nodes[i]->name,
+                             OSINFO_TREE_PROP_TREEINFO_VARIANT + strlen("treeinfo-"))) {
             osinfo_entity_set_param(OSINFO_ENTITY(tree),
                                     OSINFO_TREE_PROP_TREEINFO_VARIANT,
                                     (const gchar *)nodes[i]->children->content);
-        else if (g_str_equal((const gchar *)nodes[i]->name,
-                             OSINFO_TREE_PROP_TREEINFO_VERSION + strlen("treeinfo-")))
+            has_treeinfo = TRUE;
+        } else if (g_str_equal((const gchar *)nodes[i]->name,
+                             OSINFO_TREE_PROP_TREEINFO_VERSION + strlen("treeinfo-"))) {
             osinfo_entity_set_param(OSINFO_ENTITY(tree),
                                     OSINFO_TREE_PROP_TREEINFO_VERSION,
                                     (const gchar *)nodes[i]->children->content);
-        else if (g_str_equal((const gchar *)nodes[i]->name,
-                             OSINFO_TREE_PROP_TREEINFO_ARCH + strlen("treeinfo-")))
+            has_treeinfo = TRUE;
+        } else if (g_str_equal((const gchar *)nodes[i]->name,
+                             OSINFO_TREE_PROP_TREEINFO_ARCH + strlen("treeinfo-"))) {
             osinfo_entity_set_param(OSINFO_ENTITY(tree),
                                     OSINFO_TREE_PROP_TREEINFO_ARCH,
                                     (const gchar *)nodes[i]->children->content);
+            has_treeinfo = TRUE;
+        }
     }
 
+    osinfo_entity_set_param_boolean(OSINFO_ENTITY(tree),
+                                    OSINFO_TREE_PROP_HAS_TREEINFO,
+                                    has_treeinfo);
+
     g_free(nodes);
 
     return tree;
diff --git a/osinfo/osinfo_tree.c b/osinfo/osinfo_tree.c
index 3082eab..12d5708 100644
--- a/osinfo/osinfo_tree.c
+++ b/osinfo/osinfo_tree.c
@@ -110,6 +110,7 @@ enum {
     PROP_KERNEL_PATH,
     PROP_INITRD_PATH,
     PROP_BOOT_ISO_PATH,
+    PROP_HAS_TREEINFO,
 };
 
 static void
@@ -166,6 +167,11 @@ osinfo_tree_get_property(GObject *object,
                            osinfo_tree_get_boot_iso_path(tree));
         break;
 
+    case PROP_HAS_TREEINFO:
+        g_value_set_boolean(value,
+                            osinfo_tree_has_treeinfo(tree));
+        break;
+
     default:
         /* We don't have any other property... */
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
@@ -237,6 +243,12 @@ osinfo_tree_set_property(GObject      *object,
                                 g_value_get_string(value));
         break;
 
+    case PROP_HAS_TREEINFO:
+        osinfo_entity_set_param_boolean(OSINFO_ENTITY(tree),
+                                        OSINFO_TREE_PROP_HAS_TREEINFO,
+                                        g_value_get_boolean(value));
+        break;
+
     default:
         /* We don't have any other property... */
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
@@ -380,6 +392,18 @@ osinfo_tree_class_init(OsinfoTreeClass *klass)
                                 G_PARAM_STATIC_STRINGS);
     g_object_class_install_property(g_klass, PROP_BOOT_ISO_PATH, pspec);
 
+    /**
+     * OsinfoTree:has-treeinfo
+     *
+     * Whether the tree has treeinfo or not
+     */
+    pspec = g_param_spec_boolean("has-treeinfo",
+                                 "HasTreeinfo",
+                                 _("Whether the tree has treeinfo"),
+                                 TRUE /* default value */,
+                                 G_PARAM_READWRITE |
+                                 G_PARAM_STATIC_STRINGS);
+    g_object_class_install_property(g_klass, PROP_HAS_TREEINFO, pspec);
 }
 
 static void
@@ -842,6 +866,21 @@ const gchar *osinfo_tree_get_initrd_path(OsinfoTree *tree)
                                          OSINFO_TREE_PROP_INITRD);
 }
 
+/**
+ * osinfo_tree_has_treeinfo:
+ * @tree: and #OsinfoTree instance
+ *
+ * Return whether a tree has treeinfo or not.
+ *
+ * Returns: TRUE if the tree has treeinfo. FALSE otherwise.
+ */
+gboolean osinfo_tree_has_treeinfo(OsinfoTree *tree)
+{
+    return osinfo_entity_get_param_value_boolean_with_default(OSINFO_ENTITY(tree),
+                                                              OSINFO_TREE_PROP_HAS_TREEINFO,
+                                                              TRUE);
+}
+
 /*
  * Local variables:
  *  indent-tabs-mode: nil
diff --git a/osinfo/osinfo_tree.h b/osinfo/osinfo_tree.h
index b0b42b6..0b19b3b 100644
--- a/osinfo/osinfo_tree.h
+++ b/osinfo/osinfo_tree.h
@@ -61,6 +61,8 @@ typedef struct _OsinfoTreePrivate OsinfoTreePrivate;
 #define OSINFO_TREE_PROP_BOOT_ISO         "boot-iso"
 #define OSINFO_TREE_PROP_KERNEL           "kernel"
 #define OSINFO_TREE_PROP_INITRD           "initrd"
+#define OSINFO_TREE_PROP_HAS_TREEINFO     "has-treeinfo"
+
 
 /* object */
 struct _OsinfoTree
@@ -98,6 +100,7 @@ OsinfoTree *osinfo_tree_create_from_location_finish(GAsyncResult *res,
 
 const gchar *osinfo_tree_get_architecture(OsinfoTree *tree);
 const gchar *osinfo_tree_get_url(OsinfoTree *tree);
+gboolean osinfo_tree_has_treeinfo(OsinfoTree *tree);
 const gchar *osinfo_tree_get_treeinfo_family(OsinfoTree *tree);
 const gchar *osinfo_tree_get_treeinfo_variant(OsinfoTree *tree);
 const gchar *osinfo_tree_get_treeinfo_version(OsinfoTree *tree);
-- 
2.19.1




More information about the Libosinfo mailing list