mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-07 04:58:01 +02:00
core: merge branch 'th/fix-print-config-duplicates'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1373
(cherry picked from commit e27e250ef8)
This commit is contained in:
commit
0fa240459e
2 changed files with 41 additions and 18 deletions
|
|
@ -585,7 +585,7 @@ _merge_keyfiles(GKeyFile *keyfile_user, GKeyFile *keyfile_intern)
|
||||||
if (!keys)
|
if (!keys)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
is_intern = g_str_has_prefix(group, NM_CONFIG_KEYFILE_GROUPPREFIX_INTERN);
|
is_intern = NM_STR_HAS_PREFIX(group, NM_CONFIG_KEYFILE_GROUPPREFIX_INTERN);
|
||||||
if (!is_intern
|
if (!is_intern
|
||||||
&& g_key_file_has_key(keyfile_intern,
|
&& g_key_file_has_key(keyfile_intern,
|
||||||
group,
|
group,
|
||||||
|
|
@ -634,9 +634,11 @@ _nm_config_data_log_sort(const char **pa, const char **pb, gpointer dummy)
|
||||||
const char *a = *pa;
|
const char *a = *pa;
|
||||||
const char *b = *pb;
|
const char *b = *pb;
|
||||||
|
|
||||||
|
nm_assert(a && b && !nm_streq(a, b));
|
||||||
|
|
||||||
/* we sort intern groups to the end. */
|
/* we sort intern groups to the end. */
|
||||||
a_is_intern = g_str_has_prefix(a, NM_CONFIG_KEYFILE_GROUPPREFIX_INTERN);
|
a_is_intern = NM_STR_HAS_PREFIX(a, NM_CONFIG_KEYFILE_GROUPPREFIX_INTERN);
|
||||||
b_is_intern = g_str_has_prefix(b, NM_CONFIG_KEYFILE_GROUPPREFIX_INTERN);
|
b_is_intern = NM_STR_HAS_PREFIX(b, NM_CONFIG_KEYFILE_GROUPPREFIX_INTERN);
|
||||||
|
|
||||||
if (a_is_intern && b_is_intern)
|
if (a_is_intern && b_is_intern)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -646,8 +648,8 @@ _nm_config_data_log_sort(const char **pa, const char **pb, gpointer dummy)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* we sort connection groups before intern groups (to the end). */
|
/* we sort connection groups before intern groups (to the end). */
|
||||||
a_is_connection = a && g_str_has_prefix(a, NM_CONFIG_KEYFILE_GROUPPREFIX_CONNECTION);
|
a_is_connection = NM_STR_HAS_PREFIX(a, NM_CONFIG_KEYFILE_GROUPPREFIX_CONNECTION);
|
||||||
b_is_connection = b && g_str_has_prefix(b, NM_CONFIG_KEYFILE_GROUPPREFIX_CONNECTION);
|
b_is_connection = NM_STR_HAS_PREFIX(b, NM_CONFIG_KEYFILE_GROUPPREFIX_CONNECTION);
|
||||||
|
|
||||||
if (a_is_connection && b_is_connection) {
|
if (a_is_connection && b_is_connection) {
|
||||||
/* if both are connection groups, we want the explicit [connection] group first. */
|
/* if both are connection groups, we want the explicit [connection] group first. */
|
||||||
|
|
@ -668,8 +670,8 @@ _nm_config_data_log_sort(const char **pa, const char **pb, gpointer dummy)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* we sort device groups before connection groups (to the end). */
|
/* we sort device groups before connection groups (to the end). */
|
||||||
a_is_device = a && g_str_has_prefix(a, NM_CONFIG_KEYFILE_GROUPPREFIX_DEVICE);
|
a_is_device = NM_STR_HAS_PREFIX(a, NM_CONFIG_KEYFILE_GROUPPREFIX_DEVICE);
|
||||||
b_is_device = b && g_str_has_prefix(b, NM_CONFIG_KEYFILE_GROUPPREFIX_DEVICE);
|
b_is_device = NM_STR_HAS_PREFIX(b, NM_CONFIG_KEYFILE_GROUPPREFIX_DEVICE);
|
||||||
|
|
||||||
if (a_is_device && b_is_device) {
|
if (a_is_device && b_is_device) {
|
||||||
/* if both are device groups, we want the explicit [device] group first. */
|
/* if both are device groups, we want the explicit [device] group first. */
|
||||||
|
|
@ -770,27 +772,48 @@ nm_config_data_log(const NMConfigData *self,
|
||||||
groups_full = g_ptr_array_sized_new(ngroups + 5);
|
groups_full = g_ptr_array_sized_new(ngroups + 5);
|
||||||
|
|
||||||
if (ngroups) {
|
if (ngroups) {
|
||||||
|
/* g_key_file_get_groups() can return duplicates ( :( ), but the
|
||||||
|
* keyfile that we constructed should not have any. Assert for that. */
|
||||||
|
nm_assert(!nm_strv_has_duplicate((const char *const *) groups, ngroups, FALSE));
|
||||||
|
|
||||||
g_ptr_array_set_size(groups_full, ngroups);
|
g_ptr_array_set_size(groups_full, ngroups);
|
||||||
memcpy(groups_full->pdata, groups, sizeof(groups[0]) * ngroups);
|
memcpy(groups_full->pdata, groups, sizeof(groups[0]) * ngroups);
|
||||||
g_ptr_array_sort_with_data(groups_full, (GCompareDataFunc) _nm_config_data_log_sort, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (print_default) {
|
if (print_default) {
|
||||||
for (g = 0; g < G_N_ELEMENTS(default_values); g++) {
|
for (g = 0; g < G_N_ELEMENTS(default_values); g++) {
|
||||||
const char *group = default_values[g].group;
|
const char *group = default_values[g].group;
|
||||||
gssize idx;
|
guint g2;
|
||||||
|
|
||||||
idx = nm_utils_array_find_binary_search((gconstpointer *) groups_full->pdata,
|
if (g > 0) {
|
||||||
sizeof(char *),
|
if (nm_streq(group, default_values[g - 1].group)) {
|
||||||
groups_full->len,
|
/* Repeated values. We already added this one. Skip */
|
||||||
&group,
|
continue;
|
||||||
(GCompareDataFunc) _nm_config_data_log_sort,
|
}
|
||||||
NULL);
|
if (NM_MORE_ASSERT_ONCE(20)) {
|
||||||
if (idx < 0)
|
/* We require that the default values are grouped by their "group".
|
||||||
g_ptr_array_insert(groups_full, (~idx), (gpointer) group);
|
* That is, all default values for a certain "group" are close to
|
||||||
|
* each other in the list. Assert for that. */
|
||||||
|
for (g2 = g + 1; g2 < groups_full->len; g2++) {
|
||||||
|
nm_assert(!nm_streq(default_values[g - 1].group, default_values[g2].group));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (g2 = 0; g2 < groups_full->len; g2++) {
|
||||||
|
if (nm_streq(group, groups_full->pdata[g2]))
|
||||||
|
goto next;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_ptr_array_add(groups_full, (gpointer) group);
|
||||||
|
|
||||||
|
next:
|
||||||
|
(void) 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_ptr_array_sort_with_data(groups_full, (GCompareDataFunc) _nm_config_data_log_sort, NULL);
|
||||||
|
|
||||||
if (!stream)
|
if (!stream)
|
||||||
_LOG(stream, prefix, "config-data[%p]: %u groups", self, groups_full->len);
|
_LOG(stream, prefix, "config-data[%p]: %u groups", self, groups_full->len);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -442,7 +442,7 @@ nm_key_file_db_prune(NMKeyFileDB *self,
|
||||||
_LOGD("prune keyfile of old entries: \"%s\"", self->filename);
|
_LOGD("prune keyfile of old entries: \"%s\"", self->filename);
|
||||||
|
|
||||||
if (!self->groups_pruned) {
|
if (!self->groups_pruned) {
|
||||||
/* When we prune the first time, we swap the GKeyfile instance.
|
/* When we prune the first time, we swap the GKeyFile instance.
|
||||||
* The instance loaded from disk might have unrelated groups and
|
* The instance loaded from disk might have unrelated groups and
|
||||||
* comments. Let's get rid of them by creating a new instance.
|
* comments. Let's get rid of them by creating a new instance.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue