summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-03-13 13:42:35 +0100
committerThomas Haller <thaller@redhat.com>2015-03-15 18:28:10 +0100
commitb36dc77b77b9defba10513257f46f48f9c15a716 (patch)
tree3daa04bccc5d2300a48db1e8dccb782fd90f2214
parentbfdebae658bce4d21d25a7e91f5169f8209d79d6 (diff)
downloadNetworkManager-b36dc77b77b9defba10513257f46f48f9c15a716.tar.gz
libnm: sort settings for nm_connection_for_each_setting_value()
nm_connection_for_each_setting_value() is used by keyfile writer to iterate over the settings and write the keyfile entires. The order there is important as g_key_file_to_data() prints the groups in the order they were created. To have a stable order and to have the [connection] entry first, sort the settings.
-rw-r--r--libnm-core/nm-connection.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c
index 79ff31d89d..31107f367e 100644
--- a/libnm-core/nm-connection.c
+++ b/libnm-core/nm-connection.c
@@ -1306,6 +1306,19 @@ nm_connection_is_type (NMConnection *connection, const char *type)
return (g_strcmp0 (type2, type) == 0);
}
+static int
+_for_each_sort (NMSetting **p_a, NMSetting **p_b)
+{
+ NMSetting *a = *p_a;
+ NMSetting *b = *p_b;
+ int c;
+
+ c = _nm_setting_compare_priority (a, b);
+ if (c != 0)
+ return c;
+ return strcmp (nm_setting_get_name (a), nm_setting_get_name (b));
+}
+
/**
* nm_connection_for_each_setting_value:
* @connection: the #NMConnection
@@ -1320,15 +1333,21 @@ nm_connection_for_each_setting_value (NMConnection *connection,
NMSettingValueIterFn func,
gpointer user_data)
{
- GHashTableIter iter;
- gpointer value;
+ GPtrArray *settings;
+ guint i;
g_return_if_fail (NM_IS_CONNECTION (connection));
g_return_if_fail (func != NULL);
- g_hash_table_iter_init (&iter, NM_CONNECTION_GET_PRIVATE (connection)->settings);
- while (g_hash_table_iter_next (&iter, NULL, &value))
- nm_setting_enumerate_values (NM_SETTING (value), func, user_data);
+ settings = _nm_utils_hash_values_to_ptrarray (NM_CONNECTION_GET_PRIVATE (connection)->settings, TRUE);
+ if (settings) {
+ /* sort the settings. This has an effect on the order in which keyfile
+ * prints them. */
+ g_ptr_array_sort (settings, (GCompareFunc) _for_each_sort);
+ for (i = 0; i < settings->len; i++)
+ nm_setting_enumerate_values (g_ptr_array_index (settings, i), func, user_data);
+ g_ptr_array_unref (settings);
+ }
}
/**