libnm-core: add NM_SETTING_COMPARE_FLAG_IGNORE_TIMESTAMP flag
for ignoring timestamp when comparing settings or connections.
This commit is contained in:
@@ -1014,6 +1014,11 @@ compare_property (NMSetting *setting,
|
||||
&& g_strcmp0 (prop_spec->name, NM_SETTING_CONNECTION_ID) == 0)
|
||||
return TRUE;
|
||||
|
||||
/* Handle ignore timestamp */
|
||||
if ( (flags & NM_SETTING_COMPARE_FLAG_IGNORE_TIMESTAMP)
|
||||
&& g_strcmp0 (prop_spec->name, NM_SETTING_CONNECTION_TIMESTAMP) == 0)
|
||||
return TRUE;
|
||||
|
||||
/* Otherwise chain up to parent to handle generic compare */
|
||||
return NM_SETTING_CLASS (nm_setting_connection_parent_class)->compare_property (setting, other, prop_spec, flags);
|
||||
}
|
||||
|
@@ -1083,6 +1083,11 @@ should_compare_prop (NMSetting *setting,
|
||||
&& !strcmp (prop_name, NM_SETTING_CONNECTION_ID))
|
||||
return FALSE;
|
||||
|
||||
if ( (comp_flags & NM_SETTING_COMPARE_FLAG_IGNORE_TIMESTAMP)
|
||||
&& NM_IS_SETTING_CONNECTION (setting)
|
||||
&& !strcmp (prop_name, NM_SETTING_CONNECTION_TIMESTAMP))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@@ -110,6 +110,7 @@ typedef enum { /*< flags >*/
|
||||
* on whether the setting 'b' was available. If @NM_SETTING_COMPARE_FLAG_DIFF_RESULT_WITH_DEFAULT
|
||||
* is set, nm_setting_diff() will also set the flags @NM_SETTING_DIFF_RESULT_IN_A_DEFAULT
|
||||
* and @NM_SETTING_DIFF_RESULT_IN_B_DEFAULT, if the values are default values.
|
||||
* @NM_SETTING_COMPARE_FLAG_IGNORE_TIMESTAMP: ignore the connection's timestamp
|
||||
*
|
||||
* These flags modify the comparison behavior when comparing two settings or
|
||||
* two connections.
|
||||
@@ -124,6 +125,7 @@ typedef enum {
|
||||
NM_SETTING_COMPARE_FLAG_IGNORE_NOT_SAVED_SECRETS = 0x00000010,
|
||||
NM_SETTING_COMPARE_FLAG_DIFF_RESULT_WITH_DEFAULT = 0x00000020,
|
||||
NM_SETTING_COMPARE_FLAG_DIFF_RESULT_NO_DEFAULT = 0x00000040,
|
||||
NM_SETTING_COMPARE_FLAG_IGNORE_TIMESTAMP = 0x00000080,
|
||||
|
||||
/* 0x80000000 is used for a private flag */
|
||||
} NMSettingCompareFlags;
|
||||
|
@@ -2248,6 +2248,31 @@ test_setting_compare_id (void)
|
||||
g_assert (success);
|
||||
}
|
||||
|
||||
static void
|
||||
test_setting_compare_timestamp (void)
|
||||
{
|
||||
NMSetting *old, *new;
|
||||
gboolean success;
|
||||
|
||||
old = nm_setting_connection_new ();
|
||||
g_object_set (old,
|
||||
NM_SETTING_CONNECTION_ID, "ignore timestamp connection",
|
||||
NM_SETTING_CONNECTION_UUID, "b047a198-0e0a-4f0e-a653-eea09bb35e40",
|
||||
NM_SETTING_CONNECTION_AUTOCONNECT, FALSE,
|
||||
NM_SETTING_CONNECTION_TIMESTAMP, 1234567890,
|
||||
NULL);
|
||||
|
||||
new = nm_setting_duplicate (old);
|
||||
g_object_set (new, NM_SETTING_CONNECTION_TIMESTAMP, 1416316539, NULL);
|
||||
|
||||
/* First make sure they are different */
|
||||
success = nm_setting_compare (old, new, NM_SETTING_COMPARE_FLAG_EXACT);
|
||||
g_assert (success == FALSE);
|
||||
|
||||
success = nm_setting_compare (old, new, NM_SETTING_COMPARE_FLAG_IGNORE_TIMESTAMP);
|
||||
g_assert (success);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
NMSettingSecretFlags secret_flags;
|
||||
NMSettingCompareFlags comp_flags;
|
||||
@@ -3739,6 +3764,7 @@ int main (int argc, char **argv)
|
||||
g_test_add_func ("/core/general/test_setting_to_dbus_transform", test_setting_to_dbus_transform);
|
||||
g_test_add_func ("/core/general/test_setting_to_dbus_enum", test_setting_to_dbus_enum);
|
||||
g_test_add_func ("/core/general/test_setting_compare_id", test_setting_compare_id);
|
||||
g_test_add_func ("/core/general/test_setting_compare_timestamp", test_setting_compare_timestamp);
|
||||
#define ADD_FUNC(func, secret_flags, comp_flags, remove_secret) \
|
||||
g_test_add_data_func_full ("/core/general/" G_STRINGIFY (func), \
|
||||
test_data_compare_secrets_new (secret_flags, comp_flags, remove_secret), \
|
||||
|
Reference in New Issue
Block a user