summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel P. Berrangé <berrange@redhat.com>2021-11-25 12:29:29 +0000
committerDaniel P. Berrangé <berrange@redhat.com>2022-02-04 14:14:49 +0000
commit6a21d0ca1071fc225ef11b4cee57be3c2a62264b (patch)
treeb2ae7a8e0302157bc25812dcf594326de6f3e2a2
parentdf78f0734e59a9140d1126917d825f9f8fcd3514 (diff)
downloadlibosinfo-6a21d0ca1071fc225ef11b4cee57be3c2a62264b.tar.gz
osinfo: honour tree architecture when matching
The tree matching code currently ignores the tree architecture which is generally ok, since osinfo_tree_create_from_location will leave it set to NULL. None the less, if an architecture is provided for the unknown tree, we should only return results that match this architecture. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
-rw-r--r--osinfo/osinfo_tree.c14
-rw-r--r--tests/dbdata/os/libosinfo.org/test-tree-arm.xml29
-rw-r--r--tests/test-db.c30
-rw-r--r--tests/test-tree.c8
4 files changed, 71 insertions, 10 deletions
diff --git a/osinfo/osinfo_tree.c b/osinfo/osinfo_tree.c
index cedeadc..60deb52 100644
--- a/osinfo/osinfo_tree.c
+++ b/osinfo/osinfo_tree.c
@@ -463,9 +463,10 @@ OsinfoTree *osinfo_tree_new(const gchar *id,
"id", id,
NULL);
- osinfo_entity_set_param(OSINFO_ENTITY(tree),
- OSINFO_TREE_PROP_ARCHITECTURE,
- architecture);
+ if (architecture)
+ osinfo_entity_set_param(OSINFO_ENTITY(tree),
+ OSINFO_TREE_PROP_ARCHITECTURE,
+ architecture);
return tree;
}
@@ -1203,11 +1204,13 @@ OsinfoTree *osinfo_tree_create_from_treeinfo(const gchar *treeinfo,
*/
gboolean osinfo_tree_matches(OsinfoTree *tree, OsinfoTree *reference)
{
+ const gchar *tree_arch = osinfo_tree_get_architecture(tree);
const gchar *tree_treeinfo_family = osinfo_tree_get_treeinfo_family(tree);
const gchar *tree_treeinfo_variant = osinfo_tree_get_treeinfo_variant(tree);
const gchar *tree_treeinfo_version = osinfo_tree_get_treeinfo_version(tree);
const gchar *tree_treeinfo_arch = osinfo_tree_get_treeinfo_arch(tree);
+ const gchar *reference_arch = osinfo_tree_get_architecture(reference);
const gchar *reference_treeinfo_family = osinfo_tree_get_treeinfo_family(reference);
const gchar *reference_treeinfo_variant = osinfo_tree_get_treeinfo_variant(reference);
const gchar *reference_treeinfo_version = osinfo_tree_get_treeinfo_version(reference);
@@ -1216,7 +1219,10 @@ gboolean osinfo_tree_matches(OsinfoTree *tree, OsinfoTree *reference)
if (!osinfo_tree_has_treeinfo(reference))
return FALSE;
- if (match_regex(reference_treeinfo_family, tree_treeinfo_family) &&
+ if ((!tree_arch ||
+ g_str_equal(reference_arch, tree_arch) ||
+ g_str_equal(reference_arch, "all")) &&
+ match_regex(reference_treeinfo_family, tree_treeinfo_family) &&
match_regex(reference_treeinfo_variant, tree_treeinfo_variant) &&
match_regex(reference_treeinfo_version, tree_treeinfo_version) &&
match_regex(reference_treeinfo_arch, tree_treeinfo_arch))
diff --git a/tests/dbdata/os/libosinfo.org/test-tree-arm.xml b/tests/dbdata/os/libosinfo.org/test-tree-arm.xml
new file mode 100644
index 0000000..93162a8
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-tree-arm.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<libosinfo version="0.0.1">
+ <os id="http://libosinfo.org/test/tree/arm">
+ <short-id>tree-arm</short-id>
+ <name>TreeArm</name>
+ <version>unknown</version>
+ <vendor>libosinfo.org</vendor>
+ <family>test</family>
+
+ <tree arch="armv7hl">
+ <url>http://libosinfo.org/tree/v7</url>
+ <treeinfo>
+ <family>Tree</family>
+ <version>unknown</version>
+ <arch>arm</arch>
+ </treeinfo>
+ </tree>
+
+ <tree arch="armv6">
+ <url>http://libosinfo.org/tree/v6</url>
+ <treeinfo>
+ <family>Tree</family>
+ <version>unknown</version>
+ <arch>arm</arch>
+ </treeinfo>
+ </tree>
+
+ </os>
+</libosinfo>
diff --git a/tests/test-db.c b/tests/test-db.c
index ff645c7..32c2835 100644
--- a/tests/test-db.c
+++ b/tests/test-db.c
@@ -530,7 +530,7 @@ test_identify_media(void)
static OsinfoTree *
-create_tree(const gchar *arch, gboolean set_treeinfo_arch)
+create_tree(const gchar *arch, const gchar *treeinfo_arch)
{
OsinfoTree *tree;
@@ -541,10 +541,10 @@ create_tree(const gchar *arch, gboolean set_treeinfo_arch)
osinfo_entity_set_param(OSINFO_ENTITY(tree),
OSINFO_TREE_PROP_TREEINFO_VERSION,
"unknown");
- if (set_treeinfo_arch)
+ if (treeinfo_arch)
osinfo_entity_set_param(OSINFO_ENTITY(tree),
- OSINFO_TREE_PROP_TREEINFO_ARCH,
- arch);
+ OSINFO_TREE_PROP_TREEINFO_ARCH,
+ treeinfo_arch);
return tree;
}
@@ -564,17 +564,35 @@ test_identify_tree(void)
db = osinfo_loader_get_db(loader);
/* Matching against an "all" architecture" */
- tree = create_tree("x86_64", FALSE);
+ tree = create_tree("x86_64", NULL);
g_assert_true(osinfo_db_identify_tree(db, tree));
g_assert_cmpstr(osinfo_tree_get_architecture(tree), ==, "all");
g_object_unref(tree);
/* Matching against a known architecture, which has to have precedence */
- tree = create_tree("i686", TRUE);
+ tree = create_tree("i686", "i686");
g_assert_true(osinfo_db_identify_tree(db, tree));
g_assert_cmpstr(osinfo_tree_get_architecture(tree), ==, "i686");
g_object_unref(tree);
+ /* Matching against a known architecture, which has to have precedence */
+ tree = create_tree(NULL, "i686");
+ g_assert_true(osinfo_db_identify_tree(db, tree));
+ g_assert_cmpstr(osinfo_tree_get_architecture(tree), ==, "i686");
+ g_object_unref(tree);
+
+ /* Should not match a tree tagged with different arch, even
+ * if treeinfo matches */
+ tree = create_tree("armv7hl", "arm");
+ g_assert_true(osinfo_db_identify_tree(db, tree));
+ g_assert_cmpstr(osinfo_tree_get_url(tree), ==, "http://libosinfo.org/tree/v7");
+ g_object_unref(tree);
+
+ tree = create_tree("armv6", "arm");
+ g_assert_true(osinfo_db_identify_tree(db, tree));
+ g_assert_cmpstr(osinfo_tree_get_url(tree), ==, "http://libosinfo.org/tree/v6");
+ g_object_unref(tree);
+
g_object_unref(loader);
}
diff --git a/tests/test-tree.c b/tests/test-tree.c
index 88adccd..79d6e74 100644
--- a/tests/test-tree.c
+++ b/tests/test-tree.c
@@ -172,9 +172,17 @@ test_matching(void)
"(Server|Workstation)",
"3[0-9]",
NULL);
+ /* Mis-match on arch */
+ OsinfoTree *reference4 = test_create_tree("https://fedoraproject.org/fedora/35/tree1",
+ "i686",
+ "Fedora",
+ NULL,
+ NULL,
+ NULL);
g_assert(osinfo_tree_matches(unknown, reference1));
g_assert(!osinfo_tree_matches(unknown, reference2));
g_assert(osinfo_tree_matches(unknown, reference3));
+ g_assert(!osinfo_tree_matches(unknown, reference4));
}
int