From 093a3c88d03bf91ed65e80e45261451a50e974df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Tue, 18 Nov 2014 14:20:12 +0100 Subject: libnm-core: add NM_SETTING_COMPARE_FLAG_IGNORE_TIMESTAMP flag for ignoring timestamp when comparing settings or connections. --- libnm-core/nm-setting-connection.c | 5 +++++ libnm-core/nm-setting.c | 5 +++++ libnm-core/nm-setting.h | 2 ++ libnm-core/tests/test-general.c | 26 ++++++++++++++++++++++++++ 4 files changed, 38 insertions(+) diff --git a/libnm-core/nm-setting-connection.c b/libnm-core/nm-setting-connection.c index 323c129615..9587ebcb1b 100644 --- a/libnm-core/nm-setting-connection.c +++ b/libnm-core/nm-setting-connection.c @@ -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); } diff --git a/libnm-core/nm-setting.c b/libnm-core/nm-setting.c index 40298d3c73..45f72d0323 100644 --- a/libnm-core/nm-setting.c +++ b/libnm-core/nm-setting.c @@ -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; } diff --git a/libnm-core/nm-setting.h b/libnm-core/nm-setting.h index 5abfff9ab4..887aef4a6b 100644 --- a/libnm-core/nm-setting.h +++ b/libnm-core/nm-setting.h @@ -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; diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c index de3b9f17e3..47055d9bc6 100644 --- a/libnm-core/tests/test-general.c +++ b/libnm-core/tests/test-general.c @@ -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), \ -- cgit v1.2.1