diff options
| author | Jiří Klimeš <jklimes@redhat.com> | 2014-11-19 10:59:44 +0100 |
|---|---|---|
| committer | Jiří Klimeš <jklimes@redhat.com> | 2014-11-19 10:59:44 +0100 |
| commit | 86fd678e4e2af94d7fb395b2c284c56913479e2f (patch) | |
| tree | 560b0791cab0c435cf799a2e483b0d01de3929c9 | |
| parent | fac424b03047f66bc5d5cc27478b5447cc3042b3 (diff) | |
| parent | 265b827ddd81d5faa56f626c09acbea53c38dab3 (diff) | |
| download | NetworkManager-86fd678e4e2af94d7fb395b2c284c56913479e2f.tar.gz | |
merge: add a flag for ignoring timestamp and use it in nmcli (rh #1122995)
NM_SETTING_COMPARE_FLAG_IGNORE_TIMESTAMP can be used to ignore timestamp
while comparing connections.
https://bugzilla.redhat.com/show_bug.cgi?id=1122995
| -rw-r--r-- | clients/cli/connections.c | 2 | ||||
| -rw-r--r-- | libnm-core/nm-setting-connection.c | 5 | ||||
| -rw-r--r-- | libnm-core/nm-setting.c | 5 | ||||
| -rw-r--r-- | libnm-core/nm-setting.h | 34 | ||||
| -rw-r--r-- | libnm-core/tests/test-general.c | 26 |
5 files changed, 55 insertions, 17 deletions
diff --git a/clients/cli/connections.c b/clients/cli/connections.c index ae1250aab2..3456b92e20 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -6925,7 +6925,7 @@ is_connection_dirty (NMConnection *connection, NMRemoteConnection *remote) { return !nm_connection_compare (connection, remote ? NM_CONNECTION (remote) : NULL, - NM_SETTING_COMPARE_FLAG_EXACT); + NM_SETTING_COMPARE_FLAG_IGNORE_TIMESTAMP); } static gboolean 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 30a2c577d9..887aef4a6b 100644 --- a/libnm-core/nm-setting.h +++ b/libnm-core/nm-setting.h @@ -91,25 +91,26 @@ typedef enum { /*< flags >*/ * @NM_SETTING_COMPARE_FLAG_IGNORE_ID: ignore the connection's ID * @NM_SETTING_COMPARE_FLAG_IGNORE_SECRETS: ignore all secrets * @NM_SETTING_COMPARE_FLAG_IGNORE_AGENT_OWNED_SECRETS: ignore secrets for which - * the secret's flags indicate the secret is owned by a user secret agent - * (ie, the secret's flag includes @NM_SETTING_SECRET_FLAG_AGENT_OWNED) + * the secret's flags indicate the secret is owned by a user secret agent + * (ie, the secret's flag includes @NM_SETTING_SECRET_FLAG_AGENT_OWNED) * @NM_SETTING_COMPARE_FLAG_IGNORE_NOT_SAVED_SECRETS: ignore secrets for which - * the secret's flags indicate the secret should not be saved to persistent - * storage (ie, the secret's flag includes @NM_SETTING_SECRET_FLAG_NOT_SAVED) + * the secret's flags indicate the secret should not be saved to persistent + * storage (ie, the secret's flag includes @NM_SETTING_SECRET_FLAG_NOT_SAVED) * @NM_SETTING_COMPARE_FLAG_DIFF_RESULT_WITH_DEFAULT: if this flag is set, - * nm_setting_diff() and nm_connection_diff() will also include properties that - * are set to their default value. See also @NM_SETTING_COMPARE_FLAG_DIFF_RESULT_NO_DEFAULT. + * nm_setting_diff() and nm_connection_diff() will also include properties that + * are set to their default value. See also @NM_SETTING_COMPARE_FLAG_DIFF_RESULT_NO_DEFAULT. * @NM_SETTING_COMPARE_FLAG_DIFF_RESULT_NO_DEFAULT: if this flag is set, - * nm_setting_diff() and nm_connection_diff() will not include properties that - * are set to their default value. This is the opposite of - * @NM_SETTING_COMPARE_FLAG_DIFF_RESULT_WITH_DEFAULT. If both flags are set together, - * @NM_SETTING_COMPARE_FLAG_DIFF_RESULT_WITH_DEFAULT wins. If both flags are unset, - * this means to exclude default properties if there is a setting to compare, - * but include all properties, if the setting 'b' is missing. This is the legacy - * behaviour of libnm-util, where nm_setting_diff() behaved differently depending - * 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_diff() and nm_connection_diff() will not include properties that + * are set to their default value. This is the opposite of + * @NM_SETTING_COMPARE_FLAG_DIFF_RESULT_WITH_DEFAULT. If both flags are set together, + * @NM_SETTING_COMPARE_FLAG_DIFF_RESULT_WITH_DEFAULT wins. If both flags are unset, + * this means to exclude default properties if there is a setting to compare, + * but include all properties, if the setting 'b' is missing. This is the legacy + * behaviour of libnm-util, where nm_setting_diff() behaved differently depending + * 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), \ |
