settings: add persistent-mode argument for connection-replace

The current behavior of update_unsaved is confusing. Give the argument
an enum with a name that describes better what's happening. Also, it
makes the uses grep-able.
This commit is contained in:
Thomas Haller 2017-11-24 15:45:20 +01:00
parent c3dd5d8df2
commit 9531da8b3e
9 changed files with 52 additions and 45 deletions

View file

@ -552,13 +552,13 @@ nm_settings_connection_replace_settings_prepare (NMSettingsConnection *self,
return TRUE;
}
gboolean
nm_settings_connection_replace_settings_full (NMSettingsConnection *self,
NMConnection *new_connection,
gboolean prepare_new_connection,
gboolean update_unsaved,
const char *log_diff_name,
GError **error)
static gboolean
_replace_settings_full (NMSettingsConnection *self,
NMConnection *new_connection,
gboolean prepare_new_connection,
NMSettingsConnectionPersistMode persist_mode,
const char *log_diff_name,
GError **error)
{
NMSettingsConnectionPrivate *priv;
@ -619,8 +619,16 @@ nm_settings_connection_replace_settings_full (NMSettingsConnection *self,
/* Manually emit changed signal since we disconnected the handler, but
* only update Unsaved if the caller wanted us to.
*/
if (update_unsaved)
switch (persist_mode) {
case NM_SETTINGS_CONNECTION_PERSIST_MODE_IN_MEMORY:
set_unsaved (self, TRUE);
break;
case NM_SETTINGS_CONNECTION_PERSIST_MODE_DISK:
set_unsaved (self, FALSE);
break;
case NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP:
break;
}
g_signal_handlers_unblock_by_func (self, G_CALLBACK (connection_changed_cb), NULL);
@ -635,16 +643,16 @@ nm_settings_connection_replace_settings_full (NMSettingsConnection *self,
gboolean
nm_settings_connection_replace_settings (NMSettingsConnection *self,
NMConnection *new_connection,
gboolean update_unsaved,
NMSettingsConnectionPersistMode persist_mode,
const char *log_diff_name,
GError **error)
{
return nm_settings_connection_replace_settings_full (self,
new_connection,
TRUE,
update_unsaved,
log_diff_name,
error);
return _replace_settings_full (self,
new_connection,
TRUE,
persist_mode,
log_diff_name,
error);
}
gboolean
@ -694,14 +702,14 @@ nm_settings_connection_commit_changes (NMSettingsConnection *self,
}
if (reread_connection || new_connection) {
if (!nm_settings_connection_replace_settings_full (self,
reread_connection ?: new_connection,
!reread_connection,
FALSE,
new_connection
? "update-during-write"
: "replace-and-commit-disk",
&local)) {
if (!_replace_settings_full (self,
reread_connection ?: new_connection,
!reread_connection,
NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP,
new_connection
? "update-during-write"
: "replace-and-commit-disk",
&local)) {
/* this can't really happen, because at this point replace-settings
* is no longer supposed to fail. It's a bug. */
_LOGE ("write: replacing setting failed: %s",
@ -1711,7 +1719,7 @@ update_auth_cb (NMSettingsConnection *self,
if (info->new_settings) {
nm_settings_connection_replace_settings (self,
info->new_settings,
TRUE,
NM_SETTINGS_CONNECTION_PERSIST_MODE_IN_MEMORY,
"replace-unsaved",
&local);
}

View file

@ -140,19 +140,18 @@ gboolean nm_settings_connection_replace_settings_prepare (NMSettingsConnection *
NMConnection *new_connection,
GError **error);
typedef enum {
NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP,
NM_SETTINGS_CONNECTION_PERSIST_MODE_DISK,
NM_SETTINGS_CONNECTION_PERSIST_MODE_IN_MEMORY,
} NMSettingsConnectionPersistMode;
gboolean nm_settings_connection_replace_settings (NMSettingsConnection *self,
NMConnection *new_connection,
gboolean update_unsaved,
NMSettingsConnectionPersistMode persist_mode,
const char *log_diff_name,
GError **error);
gboolean nm_settings_connection_replace_settings_full (NMSettingsConnection *self,
NMConnection *new_connection,
gboolean prepare_new_connection,
gboolean update_unsaved,
const char *log_diff_name,
GError **error);
gboolean nm_settings_connection_delete (NMSettingsConnection *self,
GError **error);

View file

@ -62,7 +62,7 @@ nms_ibft_connection_new (const GPtrArray *block, GError **error)
/* Update settings with what was read from iscsiadm */
if (!nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (object),
source,
FALSE,
NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP,
NULL,
error))
g_clear_object (&object);

View file

@ -429,18 +429,12 @@ nm_ifcfg_connection_new (NMConnection *source,
NMConnection *tmp;
char *unhandled_spec = NULL;
const char *unmanaged_spec = NULL, *unrecognized_spec = NULL;
gboolean update_unsaved = TRUE;
g_assert (source || full_path);
if (out_ignore_error)
*out_ignore_error = FALSE;
if (full_path) {
/* The connection already is on the disk */
update_unsaved = FALSE;
}
/* If we're given a connection already, prefer that instead of re-reading */
if (source)
tmp = g_object_ref (source);
@ -466,7 +460,9 @@ nm_ifcfg_connection_new (NMConnection *source,
/* Update our settings with what was read from the file */
if (nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (object),
tmp,
update_unsaved,
full_path
? NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP /* connection is already on disk */
: NM_SETTINGS_CONNECTION_PERSIST_MODE_IN_MEMORY,
NULL,
error))
nm_ifcfg_connection_check_devtimeout (NM_IFCFG_CONNECTION (object));

View file

@ -315,7 +315,7 @@ update_connection (SettingsPluginIfcfg *self,
if (!nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (connection_by_uuid),
NM_CONNECTION (connection_new),
FALSE, /* don't set Unsaved */
NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP,
"ifcfg-update",
&local)) {
/* Shouldn't ever get here as 'connection_new' was verified by the reader already

View file

@ -188,7 +188,9 @@ nm_ifnet_connection_new (NMConnection *source, const char *conn_name)
NM_IFNET_CONNECTION_GET_PRIVATE ((NMIfnetConnection *) object)->conn_name = g_strdup (conn_name);
if (!nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (object),
tmp,
update_unsaved,
update_unsaved
? NM_SETTINGS_CONNECTION_PERSIST_MODE_IN_MEMORY
: NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP,
NULL,
NULL)) {
g_object_unref (object);

View file

@ -271,7 +271,7 @@ reload_connections (NMSettingsPlugin *config)
/* Update existing connection with new settings */
if (!nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (old),
NM_CONNECTION (new),
FALSE, /* don't set Unsaved */
NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP,
"ifnet-update",
&error)) {
/* Shouldn't ever get here as 'new' was verified by the reader already

View file

@ -161,7 +161,9 @@ nms_keyfile_connection_new (NMConnection *source,
/* Update our settings with what was read from the file */
if (!nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (object),
tmp,
update_unsaved,
update_unsaved
? NM_SETTINGS_CONNECTION_PERSIST_MODE_IN_MEMORY
: NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP,
NULL,
error)) {
g_object_unref (object);

View file

@ -260,7 +260,7 @@ update_connection (NMSKeyfilePlugin *self,
if (!nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (connection_by_uuid),
NM_CONNECTION (connection_new),
FALSE, /* don't set Unsaved */
NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP,
"keyfile-update",
&local)) {
/* Shouldn't ever get here as 'connection_new' was verified by the reader already