libnm: fix nm_connection_diff() for settings without properties
NMSettingGeneric has no properties at all. Hence, nm_connection_diff() would report that a connection A with a generic setting and a connection B without a generic setting are equal. They are not. For empty settings, let nm_setting_diff() return also empty difference hash.
This commit is contained in:
@@ -1322,6 +1322,7 @@ nm_setting_diff (NMSetting *a,
|
||||
NMSettingDiffResult a_result_default = NM_SETTING_DIFF_RESULT_IN_A_DEFAULT;
|
||||
NMSettingDiffResult b_result_default = NM_SETTING_DIFF_RESULT_IN_B_DEFAULT;
|
||||
gboolean results_created = FALSE;
|
||||
gboolean compared_any = FALSE;
|
||||
|
||||
g_return_val_if_fail (results != NULL, FALSE);
|
||||
g_return_val_if_fail (NM_IS_SETTING (a), FALSE);
|
||||
@@ -1370,6 +1371,8 @@ nm_setting_diff (NMSetting *a,
|
||||
if (strcmp (prop_spec->name, NM_SETTING_NAME) == 0)
|
||||
continue;
|
||||
|
||||
compared_any = TRUE;
|
||||
|
||||
if (b) {
|
||||
gboolean different;
|
||||
|
||||
@@ -1427,6 +1430,13 @@ nm_setting_diff (NMSetting *a,
|
||||
}
|
||||
g_free (property_specs);
|
||||
|
||||
if (!compared_any && !b) {
|
||||
/* special case: the setting has no properties, and the opposite
|
||||
* setting @b is not given. The settings differ, and we signal that
|
||||
* by returning an empty results hash. */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Don't return an empty hash table */
|
||||
if (results_created && !g_hash_table_size (*results)) {
|
||||
g_hash_table_destroy (*results);
|
||||
|
@@ -4309,8 +4309,10 @@ test_write_wired_static_with_generic (void)
|
||||
{
|
||||
gs_unref_hashtable GHashTable *diffs = NULL;
|
||||
|
||||
g_assert (nm_connection_diff (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT, &diffs));
|
||||
g_assert (!diffs);
|
||||
g_assert (!nm_connection_diff (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT, &diffs));
|
||||
g_assert (diffs);
|
||||
g_assert (g_hash_table_size (diffs) == 1);
|
||||
g_assert (g_hash_table_lookup (diffs, "generic"));
|
||||
g_assert (!nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT));
|
||||
}
|
||||
g_assert (!nm_connection_get_setting (reread, NM_TYPE_SETTING_GENERIC));
|
||||
|
Reference in New Issue
Block a user