commit 13ccc1106ac11c2e93e510cd371d620655460ebc
Author: Pavel Šimerda <psimerda@redhat.com>
Date:   Wed Aug 28 22:07:34 2013 +0200

    WIP: keyfile: use 'connections' instead of 'system-connections'
    
    Only use 'connections' directory if it exists.
    
    TODO: In one case keyfile_dir is NULL and it is not trivial to check
    that it's ok.

diff --git a/src/settings/plugins/keyfile/common.h b/src/settings/plugins/keyfile/common.h
index d48c32f..3a0db7c 100644
--- a/src/settings/plugins/keyfile/common.h
+++ b/src/settings/plugins/keyfile/common.h
@@ -26,8 +26,6 @@
 #define KEYFILE_PLUGIN_NAME "keyfile"
 #define KEYFILE_PLUGIN_INFO "(c) 2007 - 2010 Red Hat, Inc.  To report bugs please use the NetworkManager mailing list."
 
-#define KEYFILE_DIR NMCONFDIR "/system-connections"
-
 #define VPN_SECRETS_GROUP "vpn-secrets"
 
 #define KEYFILE_PLUGIN_ERROR (keyfile_plugin_error_quark ())
diff --git a/src/settings/plugins/keyfile/nm-keyfile-connection.c b/src/settings/plugins/keyfile/nm-keyfile-connection.c
index 4ef761c..42258c1 100644
--- a/src/settings/plugins/keyfile/nm-keyfile-connection.c
+++ b/src/settings/plugins/keyfile/nm-keyfile-connection.c
@@ -122,6 +122,7 @@ commit_changes (NMSettingsConnection *connection,
 	GError *error = NULL;
 
 	if (!nm_keyfile_plugin_write_connection (NM_CONNECTION (connection),
+	                                         NULL,
 	                                         priv->path,
 	                                         &path,
 	                                         &error)) {
diff --git a/src/settings/plugins/keyfile/plugin.c b/src/settings/plugins/keyfile/plugin.c
index e9041bf..4bf7b37 100644
--- a/src/settings/plugins/keyfile/plugin.c
+++ b/src/settings/plugins/keyfile/plugin.c
@@ -64,6 +64,8 @@ typedef struct {
 	GFileMonitor *conf_file_monitor;
 	guint conf_file_monitor_id;
 
+	const char *keyfile_dir;
+
 	char *hostname;
 
 	gboolean disposed;
@@ -299,7 +301,7 @@ setup_monitoring (NMSystemConfigInterface *config)
 	GFileMonitor *monitor;
 
 	if (nm_config_get_monitor_connection_files (nm_config_get ())) {
-		file = g_file_new_for_path (KEYFILE_DIR);
+		file = g_file_new_for_path (priv->keyfile_dir);
 		monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL);
 		g_object_unref (file);
 
@@ -333,10 +335,10 @@ read_connections (NMSystemConfigInterface *config)
 	GHashTableIter iter;
 	gpointer data;
 
-	dir = g_dir_open (KEYFILE_DIR, 0, &error);
+	dir = g_dir_open (priv->keyfile_dir, 0, &error);
 	if (!dir) {
 		PLUGIN_WARN (KEYFILE_PLUGIN_NAME, "Cannot read directory '%s': (%d) %s",
-		             KEYFILE_DIR,
+		             priv->keyfile_dir,
 		             error ? error->code : -1,
 		             error && error->message ? error->message : "(unknown)");
 		g_clear_error (&error);
@@ -355,7 +357,7 @@ read_connections (NMSystemConfigInterface *config)
 		if (nm_keyfile_plugin_utils_should_ignore_file (item))
 			continue;
 
-		full_path = g_build_filename (KEYFILE_DIR, item, NULL);
+		full_path = g_build_filename (priv->keyfile_dir, item, NULL);
 
 		connection = g_hash_table_lookup (oldconns, full_path);
 		if (connection) {
@@ -416,11 +418,12 @@ add_connection (NMSystemConfigInterface *config,
                 GError **error)
 {
 	SCPluginKeyfile *self = SC_PLUGIN_KEYFILE (config);
+	SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (self);
 	NMSettingsConnection *added = NULL;
 	char *path = NULL;
 
 	if (save_to_disk) {
-		if (!nm_keyfile_plugin_write_connection (connection, NULL, &path, error))
+		if (!nm_keyfile_plugin_write_connection (connection, priv->keyfile_dir, NULL, &path, error))
 			return NULL;
 	}
 		
@@ -717,6 +720,9 @@ nm_settings_keyfile_plugin_new (void)
 		priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (singleton);
 
 		priv->conf_file = nm_config_get_path (nm_config_get ());
+		priv->keyfile_dir = NMCONFDIR "/connections";
+		if (!g_file_test (priv->keyfile_dir, G_FILE_TEST_EXISTS))
+			priv->keyfile_dir = NMCONFDIR "/system-connections";
 
 		/* plugin_set_hostname() has to be called *after* priv->conf_file is set */
 		priv->hostname = plugin_get_hostname (singleton);
diff --git a/src/settings/plugins/keyfile/writer.c b/src/settings/plugins/keyfile/writer.c
index af9c318..361a7f3 100644
--- a/src/settings/plugins/keyfile/writer.c
+++ b/src/settings/plugins/keyfile/writer.c
@@ -1127,12 +1127,13 @@ out:
 
 gboolean
 nm_keyfile_plugin_write_connection (NMConnection *connection,
+                                    const char *keyfile_dir,
                                     const char *existing_path,
                                     char **out_path,
                                     GError **error)
 {
 	return _internal_write_connection (connection,
-	                                   KEYFILE_DIR,
+	                                   keyfile_dir,
 	                                   0, 0,
 	                                   existing_path,
 	                                   out_path,
diff --git a/src/settings/plugins/keyfile/writer.h b/src/settings/plugins/keyfile/writer.h
index a602f2f..726240b 100644
--- a/src/settings/plugins/keyfile/writer.h
+++ b/src/settings/plugins/keyfile/writer.h
@@ -27,6 +27,7 @@
 #include <nm-connection.h>
 
 gboolean nm_keyfile_plugin_write_connection (NMConnection *connection,
+                                             const char *keyfile_dir,
                                              const char *existing_path,
                                              char **out_path,
                                              GError **error);
