settings: implement Save() function for connections

This commit is contained in:
Dan Williams 2013-05-01 14:44:11 -05:00
parent 8a79fb1d41
commit 59222e562b
2 changed files with 42 additions and 14 deletions

View file

@ -88,6 +88,15 @@
</arg> </arg>
</method> </method>
<method name="Save">
<tp:docstring>
Saves a "dirty" connection (that had previously been
updated with UpdateUnsaved) to persistent storage.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_connection_save"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
</method>
<signal name="Updated"> <signal name="Updated">
<tp:docstring> <tp:docstring>
Emitted when any settings or permissions change. When handling Emitted when any settings or permissions change. When handling

View file

@ -56,6 +56,9 @@ static void impl_settings_connection_update_unsaved (NMSettingsConnection *conne
GHashTable *new_settings, GHashTable *new_settings,
DBusGMethodInvocation *context); DBusGMethodInvocation *context);
static void impl_settings_connection_save (NMSettingsConnection *connection,
DBusGMethodInvocation *context);
static void impl_settings_connection_delete (NMSettingsConnection *connection, static void impl_settings_connection_delete (NMSettingsConnection *connection,
DBusGMethodInvocation *context); DBusGMethodInvocation *context);
@ -1249,7 +1252,7 @@ update_auth_cb (NMSettingsConnection *self,
} }
static const char * static const char *
get_modify_permission_update (NMConnection *old, NMConnection *new) get_update_modify_permission (NMConnection *old, NMConnection *new)
{ {
NMSettingConnection *s_con; NMSettingConnection *s_con;
guint32 orig_num = 0, new_num = 0; guint32 orig_num = 0, new_num = 0;
@ -1281,9 +1284,12 @@ impl_settings_connection_update_helper (NMSettingsConnection *self,
gboolean save_to_disk) gboolean save_to_disk)
{ {
NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
NMConnection *tmp; NMConnection *tmp = NULL;
GError *error = NULL; GError *error = NULL;
UpdateInfo *info; UpdateInfo *info;
const char *permission;
g_assert (new_settings != NULL || save_to_disk == TRUE);
/* If the connection is read-only, that has to be changed at the source of /* If the connection is read-only, that has to be changed at the source of
* the problem (ex a system settings plugin that can't write connections out) * the problem (ex a system settings plugin that can't write connections out)
@ -1296,19 +1302,21 @@ impl_settings_connection_update_helper (NMSettingsConnection *self,
} }
/* Check if the settings are valid first */ /* Check if the settings are valid first */
tmp = nm_connection_new_from_hash (new_settings, &error); if (new_settings) {
if (!tmp) { tmp = nm_connection_new_from_hash (new_settings, &error);
g_assert (error); if (!tmp) {
dbus_g_method_return_error (context, error); g_assert (error);
g_error_free (error); dbus_g_method_return_error (context, error);
return; g_error_free (error);
return;
}
} }
/* And that the new connection settings will be visible to the user /* And that the new connection settings will be visible to the user
* that's sending the update request. You can't make a connection * that's sending the update request. You can't make a connection
* invisible to yourself. * invisible to yourself.
*/ */
if (!check_user_in_acl (tmp, if (!check_user_in_acl (tmp ? tmp : NM_CONNECTION (self),
context, context,
priv->session_monitor, priv->session_monitor,
NULL, NULL,
@ -1326,11 +1334,9 @@ impl_settings_connection_update_helper (NMSettingsConnection *self,
info->save_to_disk = save_to_disk; info->save_to_disk = save_to_disk;
info->new_settings = tmp; info->new_settings = tmp;
auth_start (self, permission = get_update_modify_permission (NM_CONNECTION (self),
context, tmp ? tmp : NM_CONNECTION (self));
get_modify_permission_update (NM_CONNECTION (self), info->new_settings), auth_start (self, context, permission, update_auth_cb, info);
update_auth_cb,
info);
} }
static void static void
@ -1338,6 +1344,7 @@ impl_settings_connection_update (NMSettingsConnection *self,
GHashTable *new_settings, GHashTable *new_settings,
DBusGMethodInvocation *context) DBusGMethodInvocation *context)
{ {
g_assert (new_settings);
impl_settings_connection_update_helper (self, new_settings, context, TRUE); impl_settings_connection_update_helper (self, new_settings, context, TRUE);
} }
@ -1346,9 +1353,21 @@ impl_settings_connection_update_unsaved (NMSettingsConnection *self,
GHashTable *new_settings, GHashTable *new_settings,
DBusGMethodInvocation *context) DBusGMethodInvocation *context)
{ {
g_assert (new_settings);
impl_settings_connection_update_helper (self, new_settings, context, FALSE); impl_settings_connection_update_helper (self, new_settings, context, FALSE);
} }
static void
impl_settings_connection_save (NMSettingsConnection *self,
DBusGMethodInvocation *context)
{
/* Do nothing if the connection is already synced with disk */
if (NM_SETTINGS_CONNECTION_GET_PRIVATE (self)->unsaved == TRUE)
impl_settings_connection_update_helper (self, NULL, context, TRUE);
else
dbus_g_method_return (context);
}
static void static void
con_delete_cb (NMSettingsConnection *connection, con_delete_cb (NMSettingsConnection *connection,
GError *error, GError *error,