Blob Blame History Raw
From dac6c0c2bf30af21d4876bcbd579f97cedf9f0a3 Mon Sep 17 00:00:00 2001
From: Beniamino Galvani <bgalvani@redhat.com>
Date: Wed, 20 Dec 2017 09:54:29 +0100
Subject: [PATCH] settings: clear unsaved flag on new settings-connection

When a new settings-connection is populated with the actual settings
read from disk by the plugin, calling nm_settings_connection_update()
with KEEP mode also marks it as unsaved, which should not happen on a
new connection just written to (or read from) disk.

Introduce a new KEEP_SAVED persist mode that is similar to KEEP but
clears the UNSAVED flag.

Fixes: 023ce50d2188af557b4f2af39ec5a3342612aa2f

https://bugzilla.redhat.com/show_bug.cgi?id=1525078
(cherry picked from commit 5fff928a6b746393e15487c348892b5ecaf8a416)
(cherry picked from commit b1b463d0dca46a25c5e46732949811c2c31fa4b2)
---
 src/settings/nm-settings-connection.c                   | 1 +
 src/settings/nm-settings-connection.h                   | 3 +++
 src/settings/plugins/ibft/nms-ibft-connection.c         | 2 +-
 src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c | 2 +-
 src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c     | 2 +-
 src/settings/plugins/ifnet/nms-ifnet-connection.c       | 2 +-
 src/settings/plugins/ifnet/nms-ifnet-plugin.c           | 2 +-
 src/settings/plugins/keyfile/nms-keyfile-connection.c   | 2 +-
 src/settings/plugins/keyfile/nms-keyfile-plugin.c       | 2 +-
 9 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c
index b6e894049..62f2de399 100644
--- a/src/settings/nm-settings-connection.c
+++ b/src/settings/nm-settings-connection.c
@@ -517,6 +517,7 @@ set_persist_mode (NMSettingsConnection *self, NMSettingsConnectionPersistMode pe
 		                                  TRUE);
 		return;
 	case NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP:
+	case NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP_SAVED:
 		/* Nothing to do */
 		return;
 	}
diff --git a/src/settings/nm-settings-connection.h b/src/settings/nm-settings-connection.h
index fc8ad1de1..d7a999697 100644
--- a/src/settings/nm-settings-connection.h
+++ b/src/settings/nm-settings-connection.h
@@ -137,6 +137,9 @@ gboolean nm_settings_connection_has_unmodified_applied_connection (NMSettingsCon
 
 typedef enum {
 	NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP,
+
+	/* like KEEP, but always clears the UNSAVED flag */
+	NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP_SAVED,
 	NM_SETTINGS_CONNECTION_PERSIST_MODE_DISK,
 
 	/* unsaved, only sets the unsaved flag, but it doesn't touch
diff --git a/src/settings/plugins/ibft/nms-ibft-connection.c b/src/settings/plugins/ibft/nms-ibft-connection.c
index 2a7c5f4a0..fb7f18f8d 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_update (NM_SETTINGS_CONNECTION (object),
 	                                    source,
-	                                    NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP,
+	                                    NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP_SAVED,
 	                                    NM_SETTINGS_CONNECTION_COMMIT_REASON_NONE,
 	                                    NULL,
 	                                    error))
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 3cf5c978c..6979fdaaa 100644
--- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c
+++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c
@@ -442,7 +442,7 @@ nm_ifcfg_connection_new (NMConnection *source,
 	if (nm_settings_connection_update (NM_SETTINGS_CONNECTION (object),
 	                                   tmp,
 	                                   full_path
-	                                     ? NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP /* connection is already on disk */
+	                                     ? NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP_SAVED
 	                                     : NM_SETTINGS_CONNECTION_PERSIST_MODE_UNSAVED,
 	                                   NM_SETTINGS_CONNECTION_COMMIT_REASON_NONE,
 	                                   NULL,
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 04e74bbda..2b388d1d9 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_update (NM_SETTINGS_CONNECTION (connection_by_uuid),
 			                                    NM_CONNECTION (connection_new),
-			                                    NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP,
+			                                    NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP_SAVED,
 			                                    NM_SETTINGS_CONNECTION_COMMIT_REASON_NONE,
 			                                    "ifcfg-update",
 			                                    &local)) {
diff --git a/src/settings/plugins/ifnet/nms-ifnet-connection.c b/src/settings/plugins/ifnet/nms-ifnet-connection.c
index e7cd19cd2..ce0b3f2bf 100644
--- a/src/settings/plugins/ifnet/nms-ifnet-connection.c
+++ b/src/settings/plugins/ifnet/nms-ifnet-connection.c
@@ -190,7 +190,7 @@ nm_ifnet_connection_new (NMConnection *source, const char *conn_name)
 	                                    tmp,
 	                                    update_unsaved
 	                                      ? NM_SETTINGS_CONNECTION_PERSIST_MODE_UNSAVED
-	                                      : NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP,
+	                                      : NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP_SAVED,
 	                                    NM_SETTINGS_CONNECTION_COMMIT_REASON_NONE,
 	                                    NULL,
 	                                    NULL)) {
diff --git a/src/settings/plugins/ifnet/nms-ifnet-plugin.c b/src/settings/plugins/ifnet/nms-ifnet-plugin.c
index 38d23f306..d89e988ba 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_update (NM_SETTINGS_CONNECTION (old),
 				                                    NM_CONNECTION (new),
-				                                    NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP,
+				                                    NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP_SAVED,
 				                                    NM_SETTINGS_CONNECTION_COMMIT_REASON_NONE,
 				                                    "ifnet-update",
 				                                    &error)) {
diff --git a/src/settings/plugins/keyfile/nms-keyfile-connection.c b/src/settings/plugins/keyfile/nms-keyfile-connection.c
index 5a6d8a76e..5f72a9fab 100644
--- a/src/settings/plugins/keyfile/nms-keyfile-connection.c
+++ b/src/settings/plugins/keyfile/nms-keyfile-connection.c
@@ -163,7 +163,7 @@ nms_keyfile_connection_new (NMConnection *source,
 	                                    tmp,
 	                                    update_unsaved
 	                                      ? NM_SETTINGS_CONNECTION_PERSIST_MODE_UNSAVED
-	                                      : NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP,
+	                                      : NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP_SAVED,
 	                                    NM_SETTINGS_CONNECTION_COMMIT_REASON_NONE,
 	                                    NULL,
 	                                    error)) {
diff --git a/src/settings/plugins/keyfile/nms-keyfile-plugin.c b/src/settings/plugins/keyfile/nms-keyfile-plugin.c
index bc64b3ca4..222768db4 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_update (NM_SETTINGS_CONNECTION (connection_by_uuid),
 			                                    NM_CONNECTION (connection_new),
-			                                    NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP,
+			                                    NM_SETTINGS_CONNECTION_PERSIST_MODE_KEEP_SAVED,
 			                                    NM_SETTINGS_CONNECTION_COMMIT_REASON_NONE,
 			                                    "keyfile-update",
 			                                    &local)) {
-- 
2.14.3