libnm-util: refactor hash_to_connection()

No functional change, only move the verify-step out of hash_to_connection().
This commit is contained in:
Thomas Haller 2016-03-26 12:26:54 +01:00
parent f8a6b13369
commit 6cd03bf205

View file

@ -327,13 +327,13 @@ validate_permissions_type (GHashTable *hash, GError **error)
return TRUE; return TRUE;
} }
static gboolean static void
hash_to_connection (NMConnection *connection, GHashTable *new, GError **error) hash_to_connection (NMConnection *connection, GHashTable *new)
{ {
GHashTableIter iter; GHashTableIter iter;
const char *setting_name; const char *setting_name;
GHashTable *setting_hash; GHashTable *setting_hash;
gboolean changed, valid; gboolean changed;
NMConnectionPrivate *priv = NM_CONNECTION_GET_PRIVATE (connection); NMConnectionPrivate *priv = NM_CONNECTION_GET_PRIVATE (connection);
if ((changed = g_hash_table_size (priv->settings) > 0)) if ((changed = g_hash_table_size (priv->settings) > 0))
@ -353,10 +353,8 @@ hash_to_connection (NMConnection *connection, GHashTable *new, GError **error)
} }
} }
valid = nm_connection_verify (connection, error);
if (changed) if (changed)
g_signal_emit (connection, signals[CHANGED], 0); g_signal_emit (connection, signals[CHANGED], 0);
return valid;
} }
/** /**
@ -373,16 +371,16 @@ nm_connection_replace_settings (NMConnection *connection,
GHashTable *new_settings, GHashTable *new_settings,
GError **error) GError **error)
{ {
gboolean valid = FALSE;
g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE); g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
g_return_val_if_fail (new_settings != NULL, FALSE); g_return_val_if_fail (new_settings != NULL, FALSE);
if (error) if (error)
g_return_val_if_fail (*error == NULL, FALSE); g_return_val_if_fail (*error == NULL, FALSE);
if (validate_permissions_type (new_settings, error)) if (!validate_permissions_type (new_settings, error))
valid = hash_to_connection (connection, new_settings, error); return FALSE;
return valid;
hash_to_connection (connection, new_settings);
return nm_connection_verify (connection, error);
} }
/** /**
@ -1466,10 +1464,9 @@ nm_connection_new_from_hash (GHashTable *hash, GError **error)
return NULL; return NULL;
connection = nm_connection_new (); connection = nm_connection_new ();
if (!hash_to_connection (connection, hash, error)) { hash_to_connection (connection, hash);
g_object_unref (connection); if (!nm_connection_verify (connection, error))
return NULL; g_clear_object (&connection);
}
return connection; return connection;
} }