diff options
| author | Thomas Haller <thaller@redhat.com> | 2016-05-23 10:02:04 +0200 |
|---|---|---|
| committer | Thomas Haller <thaller@redhat.com> | 2016-05-23 10:15:17 +0200 |
| commit | f664c049737a0f15b6773dab342cf531202312c5 (patch) | |
| tree | 339a35d71d506ebb1aa319fd709f7cf15ef23810 | |
| parent | 7eb9731fac2b71b741ad2302ce9e52d7019f0036 (diff) | |
| download | NetworkManager-f664c049737a0f15b6773dab342cf531202312c5.tar.gz | |
libnm/keyfile: sort entries for writing hash-of-strings
This sorts the entries of the [vpn] section alphabetically.
The sorting order doesn't really matter, but having a defined,
stable way to export a connection is preferred. Also, it looks
better when looking at the keyfile with an editor.
| -rw-r--r-- | libnm-core/nm-keyfile-writer.c | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/libnm-core/nm-keyfile-writer.c b/libnm-core/nm-keyfile-writer.c index 0ce7641c1d..f62e97c3e6 100644 --- a/libnm-core/nm-keyfile-writer.c +++ b/libnm-core/nm-keyfile-writer.c @@ -233,16 +233,23 @@ route_writer (KeyfileWriterInfo *info, write_ip_values (info->keyfile, setting_name, array, NULL, TRUE); } +static int +sort_hash_keys (gconstpointer a, gconstpointer b, gpointer user_data) +{ + return g_strcmp0 (*((const char **) a), *((const char **) b)); +} + static void write_hash_of_string (GKeyFile *file, NMSetting *setting, const char *key, const GValue *value) { - GHashTableIter iter; - const char *property = NULL, *data = NULL; + GHashTable *hash; const char *group_name = nm_setting_get_name (setting); gboolean vpn_secrets = FALSE; + gs_free const char **keys = NULL; + guint i, l; /* Write VPN secrets out to a different group to keep them separate */ if (NM_IS_SETTING_VPN (setting) && !strcmp (key, NM_SETTING_VPN_SECRETS)) { @@ -250,10 +257,19 @@ write_hash_of_string (GKeyFile *file, vpn_secrets = TRUE; } - g_hash_table_iter_init (&iter, (GHashTable *) g_value_get_boxed (value)); - while (g_hash_table_iter_next (&iter, (gpointer *) &property, (gpointer *) &data)) { + hash = g_value_get_boxed (value); + keys = (const char **) g_hash_table_get_keys_as_array (hash, &l); + if (!keys) + return; + + g_qsort_with_data (keys, l, sizeof (const char *), sort_hash_keys, NULL); + + for (i = 0; keys[i]; i++) { + const char *property, *data; gboolean write_item = TRUE; + property = keys[i]; + /* Handle VPN secrets specially; they are nested in the property's hash; * we don't want to write them if the secret is not saved, not required, * or owned by a user's secret agent. @@ -266,8 +282,10 @@ write_hash_of_string (GKeyFile *file, write_item = FALSE; } - if (write_item) + if (write_item) { + data = g_hash_table_lookup (hash, property); nm_keyfile_plugin_kf_set_string (file, group_name, property, data); + } } } |
