core: use nm_connection_replace_settings_from_connection()

And consolidate some of the code; we never need to replace the
connection's settings if nothing has changed.
This commit is contained in:
Dan Williams
2013-04-11 13:02:40 -05:00
parent bafd0d557d
commit 83baf86a27
2 changed files with 21 additions and 25 deletions

View File

@@ -373,21 +373,28 @@ secrets_cleared_cb (NMSettingsConnection *self)
*/ */
gboolean gboolean
nm_settings_connection_replace_settings (NMSettingsConnection *self, nm_settings_connection_replace_settings (NMSettingsConnection *self,
NMConnection *new, NMConnection *new_connection,
GError **error) GError **error)
{ {
NMSettingsConnectionPrivate *priv; NMSettingsConnectionPrivate *priv;
GHashTable *new_settings, *hash = NULL; GHashTable *hash = NULL;
gboolean success = FALSE; gboolean success = FALSE;
g_return_val_if_fail (NM_IS_SETTINGS_CONNECTION (self), FALSE); g_return_val_if_fail (NM_IS_SETTINGS_CONNECTION (self), FALSE);
g_return_val_if_fail (NM_IS_CONNECTION (new), FALSE); g_return_val_if_fail (NM_IS_CONNECTION (new_connection), FALSE);
priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
new_settings = nm_connection_to_hash (new, NM_SETTING_HASH_FLAG_ALL); /* Do nothing if there's nothing to update */
g_assert (new_settings); if (nm_connection_compare (NM_CONNECTION (self),
if (nm_connection_replace_settings (NM_CONNECTION (self), new_settings, error)) { new_connection,
NM_SETTING_COMPARE_FLAG_EXACT)) {
return TRUE;
}
if (nm_connection_replace_settings_from_connection (NM_CONNECTION (self),
new_connection,
error)) {
/* Cache the just-updated system secrets in case something calls /* Cache the just-updated system secrets in case something calls
* nm_connection_clear_secrets() and clears them. * nm_connection_clear_secrets() and clears them.
*/ */
@@ -407,7 +414,6 @@ nm_settings_connection_replace_settings (NMSettingsConnection *self,
nm_settings_connection_recheck_visibility (self); nm_settings_connection_recheck_visibility (self);
} }
g_hash_table_destroy (new_settings);
return success; return success;
} }
@@ -425,30 +431,20 @@ ignore_cb (NMSettingsConnection *connection,
*/ */
void void
nm_settings_connection_replace_and_commit (NMSettingsConnection *self, nm_settings_connection_replace_and_commit (NMSettingsConnection *self,
NMConnection *new, NMConnection *new_connection,
NMSettingsConnectionCommitFunc callback, NMSettingsConnectionCommitFunc callback,
gpointer user_data) gpointer user_data)
{ {
GError *error = NULL; GError *error = NULL;
g_return_if_fail (NM_IS_SETTINGS_CONNECTION (self)); g_return_if_fail (NM_IS_SETTINGS_CONNECTION (self));
g_return_if_fail (NM_IS_CONNECTION (new)); g_return_if_fail (NM_IS_CONNECTION (new_connection));
if (!callback) if (nm_settings_connection_replace_settings (self, new_connection, &error)) {
callback = ignore_cb; nm_settings_connection_commit_changes (self, callback ? callback : ignore_cb, user_data);
/* Do nothing if there's nothing to update */
if (nm_connection_compare (NM_CONNECTION (self),
NM_CONNECTION (new),
NM_SETTING_COMPARE_FLAG_EXACT)) {
callback (self, NULL, user_data);
return;
}
if (nm_settings_connection_replace_settings (self, new, &error)) {
nm_settings_connection_commit_changes (self, callback, user_data);
} else { } else {
callback (self, error, user_data); if (callback)
callback (self, error, user_data);
g_clear_error (&error); g_clear_error (&error);
} }
} }

View File

@@ -81,11 +81,11 @@ void nm_settings_connection_commit_changes (NMSettingsConnection *connection,
gpointer user_data); gpointer user_data);
gboolean nm_settings_connection_replace_settings (NMSettingsConnection *self, gboolean nm_settings_connection_replace_settings (NMSettingsConnection *self,
NMConnection *new_settings, NMConnection *new_connection,
GError **error); GError **error);
void nm_settings_connection_replace_and_commit (NMSettingsConnection *self, void nm_settings_connection_replace_and_commit (NMSettingsConnection *self,
NMConnection *new_settings, NMConnection *new_connection,
NMSettingsConnectionCommitFunc callback, NMSettingsConnectionCommitFunc callback,
gpointer user_data); gpointer user_data);