diff options
author | Richard Hughes <richard@hughsie.com> | 2016-08-10 16:04:12 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2016-08-10 17:06:43 +0100 |
commit | 3473823d2d023ee4b3dd28b44e0a7c1d97bd85c4 (patch) | |
tree | 7c45e1b789c837489d83c845210e5c2a4333cb42 /libappstream-glib/as-node.c | |
parent | c9c05176886453c8b7d904bd29caa7c8a04e9dbf (diff) | |
download | appstream-glib-3473823d2d023ee4b3dd28b44e0a7c1d97bd85c4.tar.gz |
Ensure predictable output order of XML attributes
Diffstat (limited to 'libappstream-glib/as-node.c')
-rw-r--r-- | libappstream-glib/as-node.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/libappstream-glib/as-node.c b/libappstream-glib/as-node.c index 9d651d4..c54f92d 100644 --- a/libappstream-glib/as-node.c +++ b/libappstream-glib/as-node.c @@ -213,6 +213,21 @@ as_node_add_padding (GString *xml, guint depth) g_string_append (xml, " "); } +static gint +as_node_sort_attr_by_name_cb (gconstpointer a, gconstpointer b) +{ + AsNodeAttr *attr1 = (AsNodeAttr *) a; + AsNodeAttr *attr2 = (AsNodeAttr *) b; + + /* this is always first */ + if (g_strcmp0 (attr1->key, "type") == 0) + return -1; + if (g_strcmp0 (attr2->key, "type") == 0) + return 1; + + return g_strcmp0 (attr1->key, attr2->key); +} + static gchar * as_node_get_attr_string (AsNodeData *data) { @@ -220,6 +235,9 @@ as_node_get_attr_string (AsNodeData *data) GList *l; GString *str; + /* ensure predictable output order */ + data->attrs = g_list_sort (data->attrs, as_node_sort_attr_by_name_cb); + str = g_string_new (""); for (l = data->attrs; l != NULL; l = l->next) { attr = l->data; |