diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c index 5e6c93da4a..64fec2b12d 100644 --- a/src/settings/nm-settings-connection.c +++ b/src/settings/nm-settings-connection.c @@ -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); } diff --git a/src/settings/nm-settings-connection.h b/src/settings/nm-settings-connection.h index dd9e9c213c..cb9d99879e 100644 --- a/src/settings/nm-settings-connection.h +++ b/src/settings/nm-settings-connection.h @@ -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); diff --git a/src/settings/plugins/ibft/nms-ibft-connection.c b/src/settings/plugins/ibft/nms-ibft-connection.c index 834ba83408..3c00c99fb7 100644 --- a/src/settings/plugins/ibft/nms-ibft-connection.c +++ b/src/settings/plugins/ibft/nms-ibft-connection.c @@ -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); diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c index 4c1d02ae08..5fca37fc44 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c @@ -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)); diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c index 1ebdeafa7f..9671a646b4 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c @@ -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 diff --git a/src/settings/plugins/ifnet/nms-ifnet-connection.c b/src/settings/plugins/ifnet/nms-ifnet-connection.c index 5dbb124c30..ddd8ab7162 100644 --- a/src/settings/plugins/ifnet/nms-ifnet-connection.c +++ b/src/settings/plugins/ifnet/nms-ifnet-connection.c @@ -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); diff --git a/src/settings/plugins/ifnet/nms-ifnet-plugin.c b/src/settings/plugins/ifnet/nms-ifnet-plugin.c index 998b04b47a..23a03e5ce3 100644 --- a/src/settings/plugins/ifnet/nms-ifnet-plugin.c +++ b/src/settings/plugins/ifnet/nms-ifnet-plugin.c @@ -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 diff --git a/src/settings/plugins/keyfile/nms-keyfile-connection.c b/src/settings/plugins/keyfile/nms-keyfile-connection.c index 300aa9f7b3..fe1c651339 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-connection.c +++ b/src/settings/plugins/keyfile/nms-keyfile-connection.c @@ -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); diff --git a/src/settings/plugins/keyfile/nms-keyfile-plugin.c b/src/settings/plugins/keyfile/nms-keyfile-plugin.c index dfc311af33..660990fd3b 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-plugin.c +++ b/src/settings/plugins/keyfile/nms-keyfile-plugin.c @@ -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